Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Vaishali Thakkar and committed by
Jonathan Cameron
9f59f970 293487c8

+3 -3
+3 -3
drivers/iio/light/gp2ap020a00f.c
··· 46 46 #include <linux/regmap.h> 47 47 #include <linux/regulator/consumer.h> 48 48 #include <linux/slab.h> 49 + #include <asm/unaligned.h> 49 50 #include <linux/iio/buffer.h> 50 51 #include <linux/iio/events.h> 51 52 #include <linux/iio/iio.h> ··· 967 966 struct iio_dev *indio_dev = pf->indio_dev; 968 967 struct gp2ap020a00f_data *priv = iio_priv(indio_dev); 969 968 size_t d_size = 0; 970 - __le32 light_lux; 971 969 int i, out_val, ret; 972 970 973 971 for_each_set_bit(i, indio_dev->active_scan_mask, ··· 981 981 i == GP2AP020A00F_SCAN_MODE_LIGHT_IR) { 982 982 out_val = le16_to_cpup((__le16 *)&priv->buffer[d_size]); 983 983 gp2ap020a00f_output_to_lux(priv, &out_val); 984 - light_lux = cpu_to_le32(out_val); 985 - memcpy(&priv->buffer[d_size], (u8 *)&light_lux, 4); 984 + 985 + put_unaligned_le32(out_val, &priv->buffer[d_size]); 986 986 d_size += 4; 987 987 } else { 988 988 d_size += 2;