mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dlm: Use put_unaligned_be16
@ 2015-02-01 13:38 Vaishali Thakkar
  0 siblings, 0 replies; only message in thread
From: Vaishali Thakkar @ 2015-02-01 13:38 UTC (permalink / raw)
  To: David Teigland, Christine Caulfield; +Cc: cluster-devel, linux-kernel

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-01 13:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-01 13:38 [PATCH] dlm: Use put_unaligned_be16 Vaishali Thakkar

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®