Skip to contentSkip to conversation

iio: gp2ap020a00f: Use put_unaligned_le32

PATCH Applied Vaishali Thakkar 2 participants 4 messages Feb 11, 2015 – Feb 14, 2015 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: gp2ap020a00f: Use put_unaligned_le32

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

---
 drivers/iio/light/gp2ap020a00f.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/light/gp2ap020a00f.c +2 -3
index 221ed16..650c05f 100644
@@ -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;
Signature · 1 line
1.9.1
maintainer Applied
#1 lore raw
Quoted 14 lines · Vaishali Thakkar

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

Quoted 6 lines

@@ type T; identifier tmp; @@

- T tmp;
...when != tmp

Applied to togreg branch of iio.git. Will be initially pushed out as testing for the autobuilders to play with it.

Thanks,

Quoted 28 lines
---
 drivers/iio/light/gp2ap020a00f.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/light/gp2ap020a00f.c +2 -3
index 221ed16..650c05f 100644
@@ -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;
maintainer
#2 lore raw
Quoted 15 lines · Jonathan Cameron
Quoted 14 lines · Vaishali Thakkar

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

Quoted 9 lines
Quoted 6 lines

@@ type T; identifier tmp; @@

- T tmp;
...when != tmp

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.

Quoted 35 lines

Thanks,

Quoted 18 lines
---
 drivers/iio/light/gp2ap020a00f.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/light/gp2ap020a00f.c +0 -1
index 221ed16..650c05f 100644
@@ -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,

drivers/iio/light/gp2ap020a00f.c static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data) · line 987

Quoted 10 lines
drivers/iio/light/gp2ap020a00f.c +2 -2
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 19 lines · Jonathan Cameron
Quoted 17 lines · Jonathan Cameron
Quoted 16 lines · Vaishali Thakkar

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; @@

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

- T tmp;
...when != tmp

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.

Oh...sorry.I build tested it.May be something went wrong from my side.

Anyways thanks for adding it.

Quoted 6 lines
Quoted 6 lines

Thanks,

Review

Quoted 5 lines
---
 drivers/iio/light/gp2ap020a00f.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/light/gp2ap020a00f.c

Quoted 4 lines
Quoted 4 lines

drivers/iio/light/gp2ap020a00f.c static irqreturn_t

Quoted 4 lines

index 221ed16..650c05f 100644

drivers/iio/light/gp2ap020a00f.c +0 -0
@@ -966,7 +966,6 @@ static irqreturn_t

gp2ap020a00f_trigger_handler(int irq, void *data)

Quoted 8 lines
Quoted 8 lines

drivers/iio/light/gp2ap020a00f.c static irqreturn_t

Quoted 8 lines
drivers/iio/light/gp2ap020a00f.c +0 -1
     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)

Quoted 2 lines
Quoted 2 lines

drivers/iio/light/gp2ap020a00f.c static irqreturn_t · line 981

Quoted 2 lines
drivers/iio/light/gp2ap020a00f.c +0 -0
                 i == GP2AP020A00F_SCAN_MODE_LIGHT_IR) {
                     out_val = le16_to_cpup((__le16

*)&priv->buffer[d_size]);

Quoted 3 lines
Quoted 3 lines

drivers/iio/light/gp2ap020a00f.c static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)

Quoted 3 lines
drivers/iio/light/gp2ap020a00f.c +0 -2
                     gp2ap020a00f_output_to_lux(priv, &out_val);
-                    light_lux = cpu_to_le32(out_val);
-                    memcpy(&priv->buffer[d_size], (u8 *)&light_lux,

4);

Quoted 2 lines
Quoted 2 lines

drivers/iio/light/gp2ap020a00f.c static irqreturn_t · line 984

Quoted 2 lines
drivers/iio/light/gp2ap020a00f.c +2 -0
+
+                    put_unaligned_le32(out_val,

&priv->buffer[d_size]);

Quoted 11 lines
Quoted 10 lines

drivers/iio/light/gp2ap020a00f.c static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data) · line 987

Quoted 4 lines
drivers/iio/light/gp2ap020a00f.c +0 -0
                     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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html