public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: gp2ap020a00f: Use put_unaligned_le32
@ 2015-02-11  9:17 Vaishali Thakkar
  2015-02-14 11:59 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Vaishali Thakkar @ 2015-02-11  9:17 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio,
	linux-kernel

This patch introduces the use of function put_unaligned_le32.

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

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

- tmp = cpu_to_le32(y);

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

@@ type T; identifier tmp; @@

- T tmp;
...when != tmp

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
---
 drivers/iio/light/gp2ap020a00f.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index 221ed16..650c05f 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -966,7 +966,6 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct gp2ap020a00f_data *priv = iio_priv(indio_dev);
 	size_t d_size = 0;
-	__le32 light_lux;
 	int i, out_val, ret;
 
 	for_each_set_bit(i, indio_dev->active_scan_mask,
@@ -981,8 +980,8 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
 		    i == GP2AP020A00F_SCAN_MODE_LIGHT_IR) {
 			out_val = le16_to_cpup((__le16 *)&priv->buffer[d_size]);
 			gp2ap020a00f_output_to_lux(priv, &out_val);
-			light_lux = cpu_to_le32(out_val);
-			memcpy(&priv->buffer[d_size], (u8 *)&light_lux, 4);
+
+			put_unaligned_le32(out_val, &priv->buffer[d_size]);
 			d_size += 4;
 		} else {
 			d_size += 2;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: gp2ap020a00f: Use put_unaligned_le32
  2015-02-11  9:17 [PATCH] iio: gp2ap020a00f: Use put_unaligned_le32 Vaishali Thakkar
@ 2015-02-14 11:59 ` Jonathan Cameron
  2015-02-14 17:27   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2015-02-14 11:59 UTC (permalink / raw)
  To: Vaishali Thakkar
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio,
	linux-kernel

On 11/02/15 09:17, Vaishali Thakkar wrote:
> This patch introduces the use of function put_unaligned_le32.
> 
> This is done using Coccinelle and semantic patch used is as follows:
> 
> @@ identifier tmp; expression ptr; expression y,e; type T; @@
> 
> - tmp = cpu_to_le32(y);
> 
>   <+... when != tmp
> - memcpy(ptr, (T)&tmp, ...);
> + put_unaligned_le32(y,ptr);
>   ...+>
> ? tmp = e
> 
> @@ type T; identifier tmp; @@
> 
> - T tmp;
> ...when != tmp
> 
> Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
Applied to togreg branch of iio.git.  Will be initially pushed out as
testing for the autobuilders to play with it.

Thanks,
> ---
>  drivers/iio/light/gp2ap020a00f.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
> index 221ed16..650c05f 100644
> --- a/drivers/iio/light/gp2ap020a00f.c
> +++ b/drivers/iio/light/gp2ap020a00f.c
> @@ -966,7 +966,6 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct gp2ap020a00f_data *priv = iio_priv(indio_dev);
>  	size_t d_size = 0;
> -	__le32 light_lux;
>  	int i, out_val, ret;
>  
>  	for_each_set_bit(i, indio_dev->active_scan_mask,
> @@ -981,8 +980,8 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
>  		    i == GP2AP020A00F_SCAN_MODE_LIGHT_IR) {
>  			out_val = le16_to_cpup((__le16 *)&priv->buffer[d_size]);
>  			gp2ap020a00f_output_to_lux(priv, &out_val);
> -			light_lux = cpu_to_le32(out_val);
> -			memcpy(&priv->buffer[d_size], (u8 *)&light_lux, 4);
> +
> +			put_unaligned_le32(out_val, &priv->buffer[d_size]);
>  			d_size += 4;
>  		} else {
>  			d_size += 2;
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: gp2ap020a00f: Use put_unaligned_le32
  2015-02-14 11:59 ` Jonathan Cameron
@ 2015-02-14 17:27   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2015-02-14 17:27 UTC (permalink / raw)
  To: Vaishali Thakkar
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio,
	linux-kernel

On 14/02/15 11:59, Jonathan Cameron wrote:
> On 11/02/15 09:17, Vaishali Thakkar wrote:
>> This patch introduces the use of function put_unaligned_le32.
>>
>> This is done using Coccinelle and semantic patch used is as follows:
>>
>> @@ identifier tmp; expression ptr; expression y,e; type T; @@
>>
>> - tmp = cpu_to_le32(y);
>>
>>   <+... when != tmp
>> - memcpy(ptr, (T)&tmp, ...);
>> + put_unaligned_le32(y,ptr);
>>   ...+>
>> ? tmp = e
>>
>> @@ type T; identifier tmp; @@
>>
>> - T tmp;
>> ...when != tmp
>>
>> Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
> Applied to togreg branch of iio.git.  Will be initially pushed out as
> testing for the autobuilders to play with it.
> 
This needs an include - probably asm/unaligned.h so I'll add that.
> Thanks,
>> ---
>>  drivers/iio/light/gp2ap020a00f.c | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
>> index 221ed16..650c05f 100644
>> --- a/drivers/iio/light/gp2ap020a00f.c
>> +++ b/drivers/iio/light/gp2ap020a00f.c
>> @@ -966,7 +966,6 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
>>  	struct iio_dev *indio_dev = pf->indio_dev;
>>  	struct gp2ap020a00f_data *priv = iio_priv(indio_dev);
>>  	size_t d_size = 0;
>> -	__le32 light_lux;
>>  	int i, out_val, ret;
>>  
>>  	for_each_set_bit(i, indio_dev->active_scan_mask,
>> @@ -981,8 +980,8 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
>>  		    i == GP2AP020A00F_SCAN_MODE_LIGHT_IR) {
>>  			out_val = le16_to_cpup((__le16 *)&priv->buffer[d_size]);
>>  			gp2ap020a00f_output_to_lux(priv, &out_val);
>> -			light_lux = cpu_to_le32(out_val);
>> -			memcpy(&priv->buffer[d_size], (u8 *)&light_lux, 4);
>> +
>> +			put_unaligned_le32(out_val, &priv->buffer[d_size]);
>>  			d_size += 4;
>>  		} else {
>>  			d_size += 2;
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-14 17:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-11  9:17 [PATCH] iio: gp2ap020a00f: Use put_unaligned_le32 Vaishali Thakkar
2015-02-14 11:59 ` Jonathan Cameron
2015-02-14 17:27   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox