iio: gp2ap020a00f: Use put_unaligned_le32
authorVaishali Thakkar <vthakkar1994@gmail.com>
Wed, 11 Feb 2015 09:17:27 +0000 (14:47 +0530)
committerJonathan Cameron <jic23@kernel.org>
Sat, 14 Feb 2015 17:28:41 +0000 (17:28 +0000)
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>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/light/gp2ap020a00f.c

index 221ed16de1f7babd220c81296c5eef7fdb959a0d..32b6449833faf5f6102e8b55edcb6810f2c25678 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
+#include <asm/unaligned.h>
 #include <linux/iio/buffer.h>
 #include <linux/iio/events.h>
 #include <linux/iio/iio.h>
@@ -966,7 +967,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 +981,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;