mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vaishali Thakkar <vthakkar1994@gmail.com>
To: David Teigland <teigland@redhat.com>,
	Christine Caulfield <ccaulfie@redhat.com>
Cc: cluster-devel@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH] dlm: Use put_unaligned_be16
Date: Sun, 1 Feb 2015 19:08:36 +0530	[thread overview]
Message-ID: <20150201133836.GA6056@vaishali-Ideapad-Z570> (raw)

This patch introduces the use of function put_unaligned_be16.

This is done using Coccinelle and semantic patch used is as follows:

@a@
typedef u16, __be16, uint16_t;
{u16,__be16,uint16_t} e16;
identifier tmp;
expression ptr;
expression y,e;
type T;
@@

- tmp = cpu_to_be16(y);

<+... when != tmp
(
- memcpy(ptr, (T)&tmp, \(2\|sizeof(u16)\|sizeof(__be16)\|sizeof(uint16_t)\|sizeof(e16)\));
+ put_unaligned_be16(y,ptr);
|
- memcpy(ptr, (T)&tmp, ...);
+ put_unaligned_be16(y,ptr);
)
...+>
? tmp = e

@@ type T; identifier a.tmp; @@

- T tmp;
...when != tmp

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
---
 fs/dlm/dir.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/dlm/dir.c b/fs/dlm/dir.c
index d975851..ad77747 100644
--- a/fs/dlm/dir.c
+++ b/fs/dlm/dir.c
@@ -239,7 +239,6 @@ void dlm_copy_master_names(struct dlm_ls *ls, char *inbuf, int inlen,
 	struct list_head *list;
 	struct dlm_rsb *r;
 	int offset = 0, dir_nodeid;
-	__be16 be_namelen;
 
 	down_read(&ls->ls_root_sem);
 
@@ -275,15 +274,15 @@ void dlm_copy_master_names(struct dlm_ls *ls, char *inbuf, int inlen,
 
 		if (offset + sizeof(uint16_t)*2 + r->res_length > outlen) {
 			/* Write end-of-block record */
-			be_namelen = cpu_to_be16(0);
-			memcpy(outbuf + offset, &be_namelen, sizeof(__be16));
+
+			put_unaligned_be16(0, outbuf + offset);
 			offset += sizeof(__be16);
 			ls->ls_recover_dir_sent_msg++;
 			goto out;
 		}
 
-		be_namelen = cpu_to_be16(r->res_length);
-		memcpy(outbuf + offset, &be_namelen, sizeof(__be16));
+
+		put_unaligned_be16(r->res_length, outbuf + offset);
 		offset += sizeof(__be16);
 		memcpy(outbuf + offset, r->res_name, r->res_length);
 		offset += r->res_length;
@@ -297,8 +296,8 @@ void dlm_copy_master_names(struct dlm_ls *ls, char *inbuf, int inlen,
 
 	if ((list == &ls->ls_root_list) &&
 	    (offset + sizeof(uint16_t) <= outlen)) {
-		be_namelen = cpu_to_be16(0xFFFF);
-		memcpy(outbuf + offset, &be_namelen, sizeof(__be16));
+
+		put_unaligned_be16(0xFFFF, outbuf + offset);
 		offset += sizeof(__be16);
 		ls->ls_recover_dir_sent_msg++;
 	}
-- 
1.9.1


                 reply	other threads:[~2015-02-01 13:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150201133836.GA6056@vaishali-Ideapad-Z570 \
    --to=vthakkar1994@gmail.com \
    --cc=ccaulfie@redhat.com \
    --cc=cluster-devel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=teigland@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®