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 <[email protected]>
---
 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 via email to