[OPW,kernel] Staging: lustre: Use put_unaligned_le64
diff mbox

Message ID 20141030192743.GA19260@vaishali-Ideapad-Z570
State New, archived
Headers show

Commit Message

Vaishali Thakkar Oct. 30, 2014, 7:27 p.m. UTC
This patch introduces the use of function put_unaligned_le64.

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

@@ identifier tmp; expression ptr; expression y,e; type T; @@

- tmp = cpu_to_le64(y);

  <+... when != tmp
- memcpy(ptr, (T)&tmp, ...);
+ put_unaligned_le64(y,ptr);
  ...+>
? tmp = e

@@ type T; identifier tmp; @@

- T tmp;
...when != tmp

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
---
 drivers/staging/lustre/lustre/obdclass/debug.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

Greg KH Oct. 30, 2014, 8:20 p.m. UTC | #1
On Fri, Oct 31, 2014 at 12:57:43AM +0530, Vaishali Thakkar wrote:
> This patch introduces the use of function put_unaligned_le64.
> 
> This is done using Coccinelle and semantic patch used is as follows:
> 
> @@ identifier tmp; expression ptr; expression y,e; type T; @@
> 
> - tmp = cpu_to_le64(y);
> 
>   <+... when != tmp
> - memcpy(ptr, (T)&tmp, ...);
> + put_unaligned_le64(y,ptr);
>   ...+>
> ? tmp = e
> 
> @@ type T; identifier tmp; @@
> 
> - T tmp;
> ...when != tmp
> 
> Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
> ---
>  drivers/staging/lustre/lustre/obdclass/debug.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/obdclass/debug.c b/drivers/staging/lustre/lustre/obdclass/debug.c
> index d0f8f87..5a25a0a 100644
> --- a/drivers/staging/lustre/lustre/obdclass/debug.c
> +++ b/drivers/staging/lustre/lustre/obdclass/debug.c
> @@ -60,14 +60,11 @@ int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
>  {
>  	LASSERT(addr);
>  
> -	off = cpu_to_le64 (off);
> -	id = cpu_to_le64 (id);
> -	memcpy(addr, (char *)&off, LPDS);
> -	memcpy(addr + LPDS, (char *)&id, LPDS);
> -
> +	put_unaligned_le64(off, addr);
> +	put_unaligned_le64(id, addr + LPDS);
>  	addr += len - LPDS - LPDS;
> -	memcpy(addr, (char *)&off, LPDS);
> -	memcpy(addr + LPDS, (char *)&id, LPDS);
> +	put_unaligned_le64(off, addr);
> +	put_unaligned_le64(id, addr + LPDS);
>  
>  	return 0;
>  }

Did you build this change?  It breaks the build for me:

  LD [M]  drivers/staging/rtl8188eu/r8188eu.o
drivers/staging/lustre/lustre/obdclass/debug.c: In function ‘block_debug_setup’:
drivers/staging/lustre/lustre/obdclass/debug.c:63:2: error: implicit declaration of function ‘put_unaligned_le64’ [-Werror=implicit-function-declaration]
  put_unaligned_le64(off, addr);
  ^

Please fix...
Vaishali Thakkar Oct. 31, 2014, 1:04 a.m. UTC | #2
On Fri, Oct 31, 2014 at 1:50 AM, Greg KH <gregkh@linuxfoundation.org> wrote:

> On Fri, Oct 31, 2014 at 12:57:43AM +0530, Vaishali Thakkar wrote:
> > This patch introduces the use of function put_unaligned_le64.
> >
> > This is done using Coccinelle and semantic patch used is as follows:
> >
> > @@ identifier tmp; expression ptr; expression y,e; type T; @@
> >
> > - tmp = cpu_to_le64(y);
> >
> >   <+... when != tmp
> > - memcpy(ptr, (T)&tmp, ...);
> > + put_unaligned_le64(y,ptr);
> >   ...+>
> > ? tmp = e
> >
> > @@ type T; identifier tmp; @@
> >
> > - T tmp;
> > ...when != tmp
> >
> > Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
> > ---
> >  drivers/staging/lustre/lustre/obdclass/debug.c | 11 ++++-------
> >  1 file changed, 4 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/staging/lustre/lustre/obdclass/debug.c
> b/drivers/staging/lustre/lustre/obdclass/debug.c
> > index d0f8f87..5a25a0a 100644
> > --- a/drivers/staging/lustre/lustre/obdclass/debug.c
> > +++ b/drivers/staging/lustre/lustre/obdclass/debug.c
> > @@ -60,14 +60,11 @@ int block_debug_setup(void *addr, int len, __u64
> off, __u64 id)
> >  {
> >       LASSERT(addr);
> >
> > -     off = cpu_to_le64 (off);
> > -     id = cpu_to_le64 (id);
> > -     memcpy(addr, (char *)&off, LPDS);
> > -     memcpy(addr + LPDS, (char *)&id, LPDS);
> > -
> > +     put_unaligned_le64(off, addr);
> > +     put_unaligned_le64(id, addr + LPDS);
> >       addr += len - LPDS - LPDS;
> > -     memcpy(addr, (char *)&off, LPDS);
> > -     memcpy(addr + LPDS, (char *)&id, LPDS);
> > +     put_unaligned_le64(off, addr);
> > +     put_unaligned_le64(id, addr + LPDS);
> >
> >       return 0;
> >  }
>
> Did you build this change?  It breaks the build for me:
>
>   LD [M]  drivers/staging/rtl8188eu/r8188eu.o
> drivers/staging/lustre/lustre/obdclass/debug.c: In function
> ‘block_debug_setup’:
> drivers/staging/lustre/lustre/obdclass/debug.c:63:2: error: implicit
> declaration of function ‘put_unaligned_le64’
> [-Werror=implicit-function-declaration]
>   put_unaligned_le64(off, addr);
>   ^
>
> Please fix...
>
>
Oops!! I am really sorry Greg :(  I will revise the patch.

Patch
diff mbox

diff --git a/drivers/staging/lustre/lustre/obdclass/debug.c b/drivers/staging/lustre/lustre/obdclass/debug.c
index d0f8f87..5a25a0a 100644
--- a/drivers/staging/lustre/lustre/obdclass/debug.c
+++ b/drivers/staging/lustre/lustre/obdclass/debug.c
@@ -60,14 +60,11 @@  int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
 {
 	LASSERT(addr);
 
-	off = cpu_to_le64 (off);
-	id = cpu_to_le64 (id);
-	memcpy(addr, (char *)&off, LPDS);
-	memcpy(addr + LPDS, (char *)&id, LPDS);
-
+	put_unaligned_le64(off, addr);
+	put_unaligned_le64(id, addr + LPDS);
 	addr += len - LPDS - LPDS;
-	memcpy(addr, (char *)&off, LPDS);
-	memcpy(addr + LPDS, (char *)&id, LPDS);
+	put_unaligned_le64(off, addr);
+	put_unaligned_le64(id, addr + LPDS);
 
 	return 0;
 }