Skip to contentSkip to conversation

iio: adc: intel_mrfld_adc: Use be16_to_cpu() instead of get_unaligned_be16()

PATCH In review Andy Shevchenko 2 participants 2 messages Mar 11, 2020 – Mar 15, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: intel_mrfld_adc: Use be16_to_cpu() instead of get_unaligned_be16()

There is no need to call unaligned helpers on stack placed variables because compiler will align them correctly, accordingly to architectural ABI. Moreover, using bitwise type makes it explicit to see what we are reading in bulk transfer. On top of that, use sizeof() instead of magic value.

---
 drivers/iio/adc/intel_mrfld_adc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/intel_mrfld_adc.c +3 -3
index c35a1beb817c..a6d2e1f27e76 100644
@@ -75,7 +75,7 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev,
 	struct regmap *regmap = adc->regmap;
 	unsigned int req;
 	long timeout;
-	u8 buf[2];
+	__be16 value;
 	int ret;
 
 	reinit_completion(&adc->completion);
@@ -105,11 +105,11 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev,
 		goto done;
 	}
 
-	ret = regmap_bulk_read(regmap, chan->address, buf, 2);
+	ret = regmap_bulk_read(regmap, chan->address, &value, sizeof(value));
 	if (ret)
 		goto done;
 
-	*result = get_unaligned_be16(buf);
+	*result = be16_to_cpu(value);
 	ret = IIO_VAL_INT;
 
 done:
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 7 lines · On Wed, 11 Mar 2020 11:22:23 +0200 Andy Shevchenko…

There is no need to call unaligned helpers on stack placed variables because compiler will align them correctly, accordingly to architectural ABI. Moreover, using bitwise type makes it explicit to see what we are reading in bulk transfer. On top of that, use sizeof() instead of magic value.

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

Thanks,

Jonathan

Quoted 31 lines
---
 drivers/iio/adc/intel_mrfld_adc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/intel_mrfld_adc.c +3 -3
index c35a1beb817c..a6d2e1f27e76 100644
@@ -75,7 +75,7 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev,
 	struct regmap *regmap = adc->regmap;
 	unsigned int req;
 	long timeout;
-	u8 buf[2];
+	__be16 value;
 	int ret;
 
 	reinit_completion(&adc->completion);
@@ -105,11 +105,11 @@ static int mrfld_adc_single_conv(struct iio_dev *indio_dev,
 		goto done;
 	}
 
-	ret = regmap_bulk_read(regmap, chan->address, buf, 2);
+	ret = regmap_bulk_read(regmap, chan->address, &value, sizeof(value));
 	if (ret)
 		goto done;
 
-	*result = get_unaligned_be16(buf);
+	*result = be16_to_cpu(value);
 	ret = IIO_VAL_INT;
 
 done: