All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/13] iio: Use sysfs_emit()
@ 2021-12-16 18:52 Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 01/13] iio: core: " Lars-Peter Clausen
                   ` (13 more replies)
  0 siblings, 14 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

I started the sysfs_emit() conversion during the last end-of-year break
starting with the IIO core. It is end-of-year break again, so here is a bit
more.

This series contains conversions for simple users which all follow the
pattern of `return sprintf(....)` or similar. The series also only covers
cases where the attributes are completely custom and can not be converted
to use iio_read_raw or iio_read_available. These other cases will be
handled seperately by converting them to use the IIO APIs rather than
device attributes. But this requires a bit more validation work than the
simple straigh forward conversions.

Lars-Peter Clausen (13):
  iio: core: Use sysfs_emit()
  iio: dmaengine-buffer: Use sysfs_emit()
  iio: ad7192: Use sysfs_emit()
  iio: ad9523: Use sysfs_emit()
  iio: as3935: Use sysfs_emit()
  iio: ina2xx-adc: sysfs_emit()
  iio: lm3533: Use sysfs_emit()
  iio: max31856: Use sysfs_emit()
  iio: max31865: Use sysfs_emit()
  iio: max9611: Use sysfs_emit()
  iio: ms_sensors: Use sysfs_emit()
  iio: scd4x: Use sysfs_emit()
  iio: sps30: Use sysfs_emit()

 drivers/iio/adc/ad7192.c                           | 4 ++--
 drivers/iio/adc/ina2xx-adc.c                       | 2 +-
 drivers/iio/adc/max9611.c                          | 2 +-
 drivers/iio/buffer/industrialio-buffer-dmaengine.c | 2 +-
 drivers/iio/chemical/scd4x.c                       | 2 +-
 drivers/iio/chemical/sps30.c                       | 2 +-
 drivers/iio/common/ms_sensors/ms_sensors_i2c.c     | 4 ++--
 drivers/iio/frequency/ad9523.c                     | 2 +-
 drivers/iio/industrialio-buffer.c                  | 4 ++--
 drivers/iio/industrialio-core.c                    | 2 +-
 drivers/iio/light/lm3533-als.c                     | 6 +++---
 drivers/iio/proximity/as3935.c                     | 4 ++--
 drivers/iio/temperature/max31856.c                 | 4 ++--
 drivers/iio/temperature/max31865.c                 | 4 ++--
 14 files changed, 22 insertions(+), 22 deletions(-)

-- 
2.30.2


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

* [PATCH 01/13] iio: core: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 02/13] iio: dmaengine-buffer: " Lars-Peter Clausen
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

This patch converts the places in the IIO core that follow the pattern of

   return s*printf(...)

to

   return sysfs_emit(...)

This covers the new places that have been introduced where sprintf() is
used for formatting sysfs output since the last time this was done in
commit 83ca56b663cf ("iio: core: Use sysfs_emit() (trivial bits)").

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/industrialio-buffer.c | 4 ++--
 drivers/iio/industrialio-core.c   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 94eb9f6cf128..f7721553a938 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1383,9 +1383,9 @@ static ssize_t direction_show(struct device *dev,
 
 	switch (buffer->direction) {
 	case IIO_BUFFER_DIRECTION_IN:
-		return sprintf(buf, "in\n");
+		return sysfs_emit(buf, "in\n");
 	case IIO_BUFFER_DIRECTION_OUT:
-		return sprintf(buf, "out\n");
+		return sysfs_emit(buf, "out\n");
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 20d5178ca073..25144383865c 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -747,7 +747,7 @@ static ssize_t iio_read_channel_label(struct device *dev,
 		return indio_dev->info->read_label(indio_dev, this_attr->c, buf);
 
 	if (this_attr->c->extend_name)
-		return sprintf(buf, "%s\n", this_attr->c->extend_name);
+		return sysfs_emit(buf, "%s\n", this_attr->c->extend_name);
 
 	return -EINVAL;
 }
-- 
2.30.2


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

* [PATCH 02/13] iio: dmaengine-buffer: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 01/13] iio: core: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 03/13] iio: ad7192: " Lars-Peter Clausen
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() for the `length_align_bytes` buffer attribute.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/buffer/industrialio-buffer-dmaengine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
index f8ce26a24c57..f744b62a636a 100644
--- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
+++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
@@ -136,7 +136,7 @@ static ssize_t iio_dmaengine_buffer_get_length_align(struct device *dev,
 	struct dmaengine_buffer *dmaengine_buffer =
 		iio_buffer_to_dmaengine_buffer(buffer);
 
-	return sprintf(buf, "%zu\n", dmaengine_buffer->align);
+	return sysfs_emit(buf, "%zu\n", dmaengine_buffer->align);
 }
 
 static IIO_DEVICE_ATTR(length_align_bytes, 0444,
-- 
2.30.2


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

* [PATCH 03/13] iio: ad7192: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 01/13] iio: core: " Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 02/13] iio: dmaengine-buffer: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-23 13:30   ` Jonathan Cameron
  2021-12-16 18:52 ` [PATCH 04/13] iio: ad9523: " Lars-Peter Clausen
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `ac_excication` and `bridge_swtich`
attributes of the ad7192 driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/adc/ad7192.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
index cc990205f306..47d3f56edcbc 100644
--- a/drivers/iio/adc/ad7192.c
+++ b/drivers/iio/adc/ad7192.c
@@ -433,7 +433,7 @@ static ssize_t ad7192_show_ac_excitation(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct ad7192_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", !!(st->mode & AD7192_MODE_ACX));
+	return sysfs_emit(buf, "%d\n", !!(st->mode & AD7192_MODE_ACX));
 }
 
 static ssize_t ad7192_show_bridge_switch(struct device *dev,
@@ -443,7 +443,7 @@ static ssize_t ad7192_show_bridge_switch(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct ad7192_state *st = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", !!(st->gpocon & AD7192_GPOCON_BPDSW));
+	return sysfs_emit(buf, "%d\n", !!(st->gpocon & AD7192_GPOCON_BPDSW));
 }
 
 static ssize_t ad7192_set(struct device *dev,
-- 
2.30.2


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

* [PATCH 04/13] iio: ad9523: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (2 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 03/13] iio: ad7192: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-23 13:32   ` Jonathan Cameron
  2021-12-16 18:52 ` [PATCH 05/13] iio: as3935: " Lars-Peter Clausen
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom device attributes of the ad9523
driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/frequency/ad9523.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index bdb0bc3b12dd..a0f92c336fc4 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -551,7 +551,7 @@ static ssize_t ad9523_show(struct device *dev,
 	mutex_lock(&st->lock);
 	ret = ad9523_read(indio_dev, AD9523_READBACK_0);
 	if (ret >= 0) {
-		ret = sprintf(buf, "%d\n", !!(ret & (1 <<
+		ret = sysfs_emit(buf, "%d\n", !!(ret & (1 <<
 			(u32)this_attr->address)));
 	}
 	mutex_unlock(&st->lock);
-- 
2.30.2


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

* [PATCH 05/13] iio: as3935: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (3 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 04/13] iio: ad9523: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 06/13] iio: ina2xx-adc: sysfs_emit() Lars-Peter Clausen
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `noise_level_tripped` device
attribute of the as3935 driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/proximity/as3935.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index d62766b6b39e..3eb40aa0b1e0 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -122,7 +122,7 @@ static ssize_t as3935_sensor_sensitivity_show(struct device *dev,
 		return ret;
 	val = (val & AS3935_AFE_MASK) >> 1;
 
-	return sprintf(buf, "%d\n", val);
+	return sysfs_emit(buf, "%d\n", val);
 }
 
 static ssize_t as3935_sensor_sensitivity_store(struct device *dev,
@@ -153,7 +153,7 @@ static ssize_t as3935_noise_level_tripped_show(struct device *dev,
 	int ret;
 
 	mutex_lock(&st->lock);
-	ret = sprintf(buf, "%d\n", !time_after(jiffies, st->noise_tripped + HZ));
+	ret = sysfs_emit(buf, "%d\n", !time_after(jiffies, st->noise_tripped + HZ));
 	mutex_unlock(&st->lock);
 
 	return ret;
-- 
2.30.2


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

* [PATCH 06/13] iio: ina2xx-adc: sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (4 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 05/13] iio: as3935: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 07/13] iio: lm3533: Use sysfs_emit() Lars-Peter Clausen
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `in_allow_async_readout` device
attribute of the ina2xx-adc driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/adc/ina2xx-adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 352f27657238..4e66473b0821 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -539,7 +539,7 @@ static ssize_t ina2xx_allow_async_readout_show(struct device *dev,
 {
 	struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev));
 
-	return sprintf(buf, "%d\n", chip->allow_async_readout);
+	return sysfs_emit(buf, "%d\n", chip->allow_async_readout);
 }
 
 static ssize_t ina2xx_allow_async_readout_store(struct device *dev,
-- 
2.30.2


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

* [PATCH 07/13] iio: lm3533: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (5 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 06/13] iio: ina2xx-adc: sysfs_emit() Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-17  9:14   ` Johan Hovold
  2021-12-16 18:52 ` [PATCH 08/13] iio: max31856: " Lars-Peter Clausen
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom device attributes of the lm3533
driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/light/lm3533-als.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
index 8a621244dd01..827bc25269e9 100644
--- a/drivers/iio/light/lm3533-als.c
+++ b/drivers/iio/light/lm3533-als.c
@@ -417,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,
 		enable = 0;
 	}
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", enable);
+	return sysfs_emit(buf, "%u\n", enable);
 }
 
 static ssize_t store_thresh_either_en(struct device *dev,
@@ -474,7 +474,7 @@ static ssize_t show_zone(struct device *dev,
 	if (ret)
 		return ret;
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", zone);
+	return sysfs_emit(buf, "%u\n", zone);
 }
 
 enum lm3533_als_attribute_type {
@@ -530,7 +530,7 @@ static ssize_t show_als_attr(struct device *dev,
 	if (ret)
 		return ret;
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", val);
+	return sysfs_emit(buf, "%u\n", val);
 }
 
 static ssize_t store_als_attr(struct device *dev,
-- 
2.30.2


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

* [PATCH 08/13] iio: max31856: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (6 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 07/13] iio: lm3533: Use sysfs_emit() Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 09/13] iio: max31865: " Lars-Peter Clausen
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `fault_ovuv`, `fault_oc` and
`in_temp_filter_notch_center_frequency` device attributes of the max31856
driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/temperature/max31856.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/temperature/max31856.c b/drivers/iio/temperature/max31856.c
index 1954322e43be..54840881259a 100644
--- a/drivers/iio/temperature/max31856.c
+++ b/drivers/iio/temperature/max31856.c
@@ -320,7 +320,7 @@ static ssize_t show_fault(struct device *dev, u8 faultbit, char *buf)
 
 	fault = reg_val & faultbit;
 
-	return sprintf(buf, "%d\n", fault);
+	return sysfs_emit(buf, "%d\n", fault);
 }
 
 static ssize_t show_fault_ovuv(struct device *dev,
@@ -344,7 +344,7 @@ static ssize_t show_filter(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct max31856_data *data = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", data->filter_50hz ? 50 : 60);
+	return sysfs_emit(buf, "%d\n", data->filter_50hz ? 50 : 60);
 }
 
 static ssize_t set_filter(struct device *dev,
-- 
2.30.2


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

* [PATCH 09/13] iio: max31865: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (7 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 08/13] iio: max31856: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 10/13] iio: max9611: " Lars-Peter Clausen
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom ``in_filter_notch_center_frequency`
and fault_ovuv` device attributes of the max31865 driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/temperature/max31865.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/temperature/max31865.c b/drivers/iio/temperature/max31865.c
index 4c8d6e6cf677..86c3f3509a26 100644
--- a/drivers/iio/temperature/max31865.c
+++ b/drivers/iio/temperature/max31865.c
@@ -208,7 +208,7 @@ static ssize_t show_fault(struct device *dev, u8 faultbit, char *buf)
 
 	fault = data->buf[0] & faultbit;
 
-	return sprintf(buf, "%d\n", fault);
+	return sysfs_emit(buf, "%d\n", fault);
 }
 
 static ssize_t show_fault_ovuv(struct device *dev,
@@ -225,7 +225,7 @@ static ssize_t show_filter(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct max31865_data *data = iio_priv(indio_dev);
 
-	return sprintf(buf, "%d\n", data->filter_50hz ? 50 : 60);
+	return sysfs_emit(buf, "%d\n", data->filter_50hz ? 50 : 60);
 }
 
 static ssize_t set_filter(struct device *dev,
-- 
2.30.2


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

* [PATCH 10/13] iio: max9611: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (8 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 09/13] iio: max31865: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-17  9:05   ` Jacopo Mondi
  2021-12-16 18:52 ` [PATCH 11/13] iio: ms_sensors: " Lars-Peter Clausen
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
`in_current_shunt_resistor` device attributes of the max9611 driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/adc/max9611.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c
index 01a4275e9c46..f982f00303dc 100644
--- a/drivers/iio/adc/max9611.c
+++ b/drivers/iio/adc/max9611.c
@@ -429,7 +429,7 @@ static ssize_t max9611_shunt_resistor_show(struct device *dev,
 	i = max9611->shunt_resistor_uohm / 1000000;
 	r = max9611->shunt_resistor_uohm % 1000000;
 
-	return sprintf(buf, "%u.%06u\n", i, r);
+	return sysfs_emit(buf, "%u.%06u\n", i, r);
 }
 
 static IIO_DEVICE_ATTR(in_power_shunt_resistor, 0444,
-- 
2.30.2


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

* [PATCH 11/13] iio: ms_sensors: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (9 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 10/13] iio: max9611: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 12/13] iio: scd4x: " Lars-Peter Clausen
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `battery_low` and `heater_enable`
device attributes of the ms_sensors driver shared code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/common/ms_sensors/ms_sensors_i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c
index 16ea697e945c..3eb790aec4b2 100644
--- a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c
+++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c
@@ -324,7 +324,7 @@ ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data,
 	if (ret)
 		return ret;
 
-	return sprintf(buf, "%d\n", (config_reg & 0x40) >> 6);
+	return sysfs_emit(buf, "%d\n", (config_reg & 0x40) >> 6);
 }
 EXPORT_SYMBOL(ms_sensors_show_battery_low);
 
@@ -351,7 +351,7 @@ ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data,
 	if (ret)
 		return ret;
 
-	return sprintf(buf, "%d\n", (config_reg & 0x4) >> 2);
+	return sysfs_emit(buf, "%d\n", (config_reg & 0x4) >> 2);
 }
 EXPORT_SYMBOL(ms_sensors_show_heater);
 
-- 
2.30.2


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

* [PATCH 12/13] iio: scd4x: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (10 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 11/13] iio: ms_sensors: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2021-12-16 18:52 ` [PATCH 13/13] iio: sps30: " Lars-Peter Clausen
  2022-01-16 16:54 ` [PATCH 00/13] iio: " Jonathan Cameron
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `calibration_auto_enable` device
attribute of the scd4x driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/chemical/scd4x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/chemical/scd4x.c b/drivers/iio/chemical/scd4x.c
index 267bc3c05338..20d4e7584e92 100644
--- a/drivers/iio/chemical/scd4x.c
+++ b/drivers/iio/chemical/scd4x.c
@@ -423,7 +423,7 @@ static ssize_t calibration_auto_enable_show(struct device *dev,
 
 	val = (be16_to_cpu(bval) & SCD4X_READY_MASK) ? 1 : 0;
 
-	return sprintf(buf, "%d\n", val);
+	return sysfs_emit(buf, "%d\n", val);
 }
 
 static ssize_t calibration_auto_enable_store(struct device *dev,
-- 
2.30.2


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

* [PATCH 13/13] iio: sps30: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (11 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 12/13] iio: scd4x: " Lars-Peter Clausen
@ 2021-12-16 18:52 ` Lars-Peter Clausen
  2022-01-16 16:54 ` [PATCH 00/13] iio: " Jonathan Cameron
  13 siblings, 0 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-16 18:52 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio, Lars-Peter Clausen

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.

Use sysfs_emit() to format the custom `cleaning_period` device attribute of
the sps30 driver.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/chemical/sps30.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c
index d51314505115..abd67559e451 100644
--- a/drivers/iio/chemical/sps30.c
+++ b/drivers/iio/chemical/sps30.c
@@ -221,7 +221,7 @@ static ssize_t cleaning_period_show(struct device *dev,
 	if (ret)
 		return ret;
 
-	return sprintf(buf, "%d\n", be32_to_cpu(val));
+	return sysfs_emit(buf, "%d\n", be32_to_cpu(val));
 }
 
 static ssize_t cleaning_period_store(struct device *dev, struct device_attribute *attr,
-- 
2.30.2


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

* Re: [PATCH 10/13] iio: max9611: Use sysfs_emit()
  2021-12-16 18:52 ` [PATCH 10/13] iio: max9611: " Lars-Peter Clausen
@ 2021-12-17  9:05   ` Jacopo Mondi
  2021-12-17  9:17     ` Lars-Peter Clausen
  0 siblings, 1 reply; 22+ messages in thread
From: Jacopo Mondi @ 2021-12-17  9:05 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, Alexandru Tachici,
	Roan van Dijk, Tomasz Duszynski, Marc Titinger, Matt Ranostay,
	Johan Hovold, Paresh Chaudhary, Navin Sankar Velliangiri,
	Jacopo Mondi, Ludovic Tancerel, linux-iio

Hi Lars-Peter,

On Thu, Dec 16, 2021 at 07:52:14PM +0100, Lars-Peter Clausen wrote:
> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> knows about the sysfs buffer specifics and has some built-in checks for
> size and alignment.
>
> Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
> `in_current_shunt_resistor` device attributes of the max9611 driver.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

Looks good, I just wonder if a dependency on the CONFIG_SYSFS symbol
should now be added...

Thanks
   j

> ---
>  drivers/iio/adc/max9611.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c
> index 01a4275e9c46..f982f00303dc 100644
> --- a/drivers/iio/adc/max9611.c
> +++ b/drivers/iio/adc/max9611.c
> @@ -429,7 +429,7 @@ static ssize_t max9611_shunt_resistor_show(struct device *dev,
>  	i = max9611->shunt_resistor_uohm / 1000000;
>  	r = max9611->shunt_resistor_uohm % 1000000;
>
> -	return sprintf(buf, "%u.%06u\n", i, r);
> +	return sysfs_emit(buf, "%u.%06u\n", i, r);
>  }
>
>  static IIO_DEVICE_ATTR(in_power_shunt_resistor, 0444,
> --
> 2.30.2
>

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

* Re: [PATCH 07/13] iio: lm3533: Use sysfs_emit()
  2021-12-16 18:52 ` [PATCH 07/13] iio: lm3533: Use sysfs_emit() Lars-Peter Clausen
@ 2021-12-17  9:14   ` Johan Hovold
  2022-01-16 16:50     ` Jonathan Cameron
  0 siblings, 1 reply; 22+ messages in thread
From: Johan Hovold @ 2021-12-17  9:14 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, Alexandru Tachici,
	Roan van Dijk, Tomasz Duszynski, Marc Titinger, Matt Ranostay,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio

On Thu, Dec 16, 2021 at 07:52:11PM +0100, Lars-Peter Clausen wrote:
> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> knows about the sysfs buffer specifics and has some built-in checks for
> size and alignment.

I realise that the above is some copy-paste boiler plate, but none of it
is really relevant here when the driver uses the attribute buffer
directly with scnprintf() and a PAGE_SIZE argument.

This should probably be rephrased in terms of consistency and the
documentation now claiming that only sysfs_emit() should be used in
show() functions (e.g. to avoid problems in drivers that would have
failed to follow the previous instructions).

> Use sysfs_emit() to format the custom device attributes of the lm3533
> driver.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

That said, the change itself is otherwise fine even I'm not sure it's
generally worth the churn to convert all existing show() functions:

Reviewed-by: Johan Hovold <johan@kernel.org>

> ---
>  drivers/iio/light/lm3533-als.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
> index 8a621244dd01..827bc25269e9 100644
> --- a/drivers/iio/light/lm3533-als.c
> +++ b/drivers/iio/light/lm3533-als.c
> @@ -417,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,
>  		enable = 0;
>  	}
>  
> -	return scnprintf(buf, PAGE_SIZE, "%u\n", enable);
> +	return sysfs_emit(buf, "%u\n", enable);
>  }
>  
>  static ssize_t store_thresh_either_en(struct device *dev,
> @@ -474,7 +474,7 @@ static ssize_t show_zone(struct device *dev,
>  	if (ret)
>  		return ret;
>  
> -	return scnprintf(buf, PAGE_SIZE, "%u\n", zone);
> +	return sysfs_emit(buf, "%u\n", zone);
>  }
>  
>  enum lm3533_als_attribute_type {
> @@ -530,7 +530,7 @@ static ssize_t show_als_attr(struct device *dev,
>  	if (ret)
>  		return ret;
>  
> -	return scnprintf(buf, PAGE_SIZE, "%u\n", val);
> +	return sysfs_emit(buf, "%u\n", val);
>  }
>  
>  static ssize_t store_als_attr(struct device *dev,

Johan

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

* Re: [PATCH 10/13] iio: max9611: Use sysfs_emit()
  2021-12-17  9:05   ` Jacopo Mondi
@ 2021-12-17  9:17     ` Lars-Peter Clausen
  2021-12-17 10:09       ` Jacopo Mondi
  0 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2021-12-17  9:17 UTC (permalink / raw)
  To: Jacopo Mondi
  Cc: Jonathan Cameron, Michael Hennerich, Alexandru Tachici,
	Roan van Dijk, Tomasz Duszynski, Marc Titinger, Matt Ranostay,
	Johan Hovold, Paresh Chaudhary, Navin Sankar Velliangiri,
	Jacopo Mondi, Ludovic Tancerel, linux-iio

On 12/17/21 10:05 AM, Jacopo Mondi wrote:
> Hi Lars-Peter,
>
> On Thu, Dec 16, 2021 at 07:52:14PM +0100, Lars-Peter Clausen wrote:
>> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
>> knows about the sysfs buffer specifics and has some built-in checks for
>> size and alignment.
>>
>> Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
>> `in_current_shunt_resistor` device attributes of the max9611 driver.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Looks good, I just wonder if a dependency on the CONFIG_SYSFS symbol
> should now be added...
>
I don't think anything has changed in this regard. The function is 
called from a sysfs attribute callback. If SYSFS is disabled the 
callback will not be called. At the same time sysfs_emit() is stubbed 
out when SYSFS is disabled, so no compile error either.

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

* Re: [PATCH 10/13] iio: max9611: Use sysfs_emit()
  2021-12-17  9:17     ` Lars-Peter Clausen
@ 2021-12-17 10:09       ` Jacopo Mondi
  0 siblings, 0 replies; 22+ messages in thread
From: Jacopo Mondi @ 2021-12-17 10:09 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, Alexandru Tachici,
	Roan van Dijk, Tomasz Duszynski, Marc Titinger, Matt Ranostay,
	Johan Hovold, Paresh Chaudhary, Navin Sankar Velliangiri,
	Jacopo Mondi, Ludovic Tancerel, linux-iio


On Fri, Dec 17, 2021 at 10:17:58AM +0100, Lars-Peter Clausen wrote:
> On 12/17/21 10:05 AM, Jacopo Mondi wrote:
> > Hi Lars-Peter,
> >
> > On Thu, Dec 16, 2021 at 07:52:14PM +0100, Lars-Peter Clausen wrote:
> > > sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> > > knows about the sysfs buffer specifics and has some built-in checks for
> > > size and alignment.
> > >
> > > Use sysfs_emit() to format the custom `in_power_shunt_resistor` and
> > > `in_current_shunt_resistor` device attributes of the max9611 driver.
> > >
> > > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> > Looks good, I just wonder if a dependency on the CONFIG_SYSFS symbol
> > should now be added...
> >
> I don't think anything has changed in this regard. The function is called
> from a sysfs attribute callback. If SYSFS is disabled the callback will not
> be called. At the same time sysfs_emit() is stubbed out when SYSFS is
> disabled, so no compile error either.

You're right, nothing changes, we won't have any attribute to call the
function on :)

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks!
   j

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

* Re: [PATCH 03/13] iio: ad7192: Use sysfs_emit()
  2021-12-16 18:52 ` [PATCH 03/13] iio: ad7192: " Lars-Peter Clausen
@ 2021-12-23 13:30   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2021-12-23 13:30 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio

On Thu, 16 Dec 2021 19:52:07 +0100
Lars-Peter Clausen <lars@metafoo.de> wrote:

> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> knows about the sysfs buffer specifics and has some built-in checks for
> size and alignment.
> 
> Use sysfs_emit() to format the custom `ac_excication` and `bridge_swtich`
excitation

I'll fix up whilst applying if this doesn't need a respin for other reasons.

> attributes of the ad7192 driver.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>  drivers/iio/adc/ad7192.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index cc990205f306..47d3f56edcbc 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -433,7 +433,7 @@ static ssize_t ad7192_show_ac_excitation(struct device *dev,
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct ad7192_state *st = iio_priv(indio_dev);
>  
> -	return sprintf(buf, "%d\n", !!(st->mode & AD7192_MODE_ACX));
> +	return sysfs_emit(buf, "%d\n", !!(st->mode & AD7192_MODE_ACX));
>  }
>  
>  static ssize_t ad7192_show_bridge_switch(struct device *dev,
> @@ -443,7 +443,7 @@ static ssize_t ad7192_show_bridge_switch(struct device *dev,
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct ad7192_state *st = iio_priv(indio_dev);
>  
> -	return sprintf(buf, "%d\n", !!(st->gpocon & AD7192_GPOCON_BPDSW));
> +	return sysfs_emit(buf, "%d\n", !!(st->gpocon & AD7192_GPOCON_BPDSW));
>  }
>  
>  static ssize_t ad7192_set(struct device *dev,


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

* Re: [PATCH 04/13] iio: ad9523: Use sysfs_emit()
  2021-12-16 18:52 ` [PATCH 04/13] iio: ad9523: " Lars-Peter Clausen
@ 2021-12-23 13:32   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2021-12-23 13:32 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio

On Thu, 16 Dec 2021 19:52:08 +0100
Lars-Peter Clausen <lars@metafoo.de> wrote:

> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> knows about the sysfs buffer specifics and has some built-in checks for
> size and alignment.
> 
> Use sysfs_emit() to format the custom device attributes of the ad9523
> driver.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>  drivers/iio/frequency/ad9523.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
> index bdb0bc3b12dd..a0f92c336fc4 100644
> --- a/drivers/iio/frequency/ad9523.c
> +++ b/drivers/iio/frequency/ad9523.c
> @@ -551,7 +551,7 @@ static ssize_t ad9523_show(struct device *dev,
>  	mutex_lock(&st->lock);
>  	ret = ad9523_read(indio_dev, AD9523_READBACK_0);
>  	if (ret >= 0) {
> -		ret = sprintf(buf, "%d\n", !!(ret & (1 <<
> +		ret = sysfs_emit(buf, "%d\n", !!(ret & (1 <<
>  			(u32)this_attr->address)));

Obviously not due to this patch, but that's some horrible line breaking.
I might just tidy that up whilst applying this - or send a follow up to
do it.

>  	}
>  	mutex_unlock(&st->lock);


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

* Re: [PATCH 07/13] iio: lm3533: Use sysfs_emit()
  2021-12-17  9:14   ` Johan Hovold
@ 2022-01-16 16:50     ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2022-01-16 16:50 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Lars-Peter Clausen, Michael Hennerich, Alexandru Tachici,
	Roan van Dijk, Tomasz Duszynski, Marc Titinger, Matt Ranostay,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio

On Fri, 17 Dec 2021 10:14:49 +0100
Johan Hovold <johan@kernel.org> wrote:

> On Thu, Dec 16, 2021 at 07:52:11PM +0100, Lars-Peter Clausen wrote:
> > sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> > knows about the sysfs buffer specifics and has some built-in checks for
> > size and alignment.  
> 
> I realise that the above is some copy-paste boiler plate, but none of it
> is really relevant here when the driver uses the attribute buffer
> directly with scnprintf() and a PAGE_SIZE argument.
> 
> This should probably be rephrased in terms of consistency and the
> documentation now claiming that only sysfs_emit() should be used in
> show() functions (e.g. to avoid problems in drivers that would have
> failed to follow the previous instructions).
> 
I've added some stuff about best practice and chances of being copied into
new drives to this text.

> > Use sysfs_emit() to format the custom device attributes of the lm3533
> > driver.
> > 
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>  
> 
> That said, the change itself is otherwise fine even I'm not sure it's
> generally worth the churn to convert all existing show() functions:

Agreed it's not an activity I'd consider of high importance but there
is definitely advantage in updating drivers to current best practice
because it saves having to comment on it as often in reviews.

> 
> Reviewed-by: Johan Hovold <johan@kernel.org>

Thanks,

Jonathan
> 
> > ---
> >  drivers/iio/light/lm3533-als.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
> > index 8a621244dd01..827bc25269e9 100644
> > --- a/drivers/iio/light/lm3533-als.c
> > +++ b/drivers/iio/light/lm3533-als.c
> > @@ -417,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,
> >  		enable = 0;
> >  	}
> >  
> > -	return scnprintf(buf, PAGE_SIZE, "%u\n", enable);
> > +	return sysfs_emit(buf, "%u\n", enable);
> >  }
> >  
> >  static ssize_t store_thresh_either_en(struct device *dev,
> > @@ -474,7 +474,7 @@ static ssize_t show_zone(struct device *dev,
> >  	if (ret)
> >  		return ret;
> >  
> > -	return scnprintf(buf, PAGE_SIZE, "%u\n", zone);
> > +	return sysfs_emit(buf, "%u\n", zone);
> >  }
> >  
> >  enum lm3533_als_attribute_type {
> > @@ -530,7 +530,7 @@ static ssize_t show_als_attr(struct device *dev,
> >  	if (ret)
> >  		return ret;
> >  
> > -	return scnprintf(buf, PAGE_SIZE, "%u\n", val);
> > +	return sysfs_emit(buf, "%u\n", val);
> >  }
> >  
> >  static ssize_t store_als_attr(struct device *dev,  
> 
> Johan


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

* Re: [PATCH 00/13] iio: Use sysfs_emit()
  2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
                   ` (12 preceding siblings ...)
  2021-12-16 18:52 ` [PATCH 13/13] iio: sps30: " Lars-Peter Clausen
@ 2022-01-16 16:54 ` Jonathan Cameron
  13 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2022-01-16 16:54 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Michael Hennerich, Alexandru Tachici, Roan van Dijk,
	Tomasz Duszynski, Marc Titinger, Matt Ranostay, Johan Hovold,
	Paresh Chaudhary, Navin Sankar Velliangiri, Jacopo Mondi,
	Ludovic Tancerel, linux-iio

On Thu, 16 Dec 2021 19:52:04 +0100
Lars-Peter Clausen <lars@metafoo.de> wrote:

> I started the sysfs_emit() conversion during the last end-of-year break
> starting with the IIO core. It is end-of-year break again, so here is a bit
> more.
> 
> This series contains conversions for simple users which all follow the
> pattern of `return sprintf(....)` or similar. The series also only covers
> cases where the attributes are completely custom and can not be converted
> to use iio_read_raw or iio_read_available. These other cases will be
> handled seperately by converting them to use the IIO APIs rather than
> device attributes. But this requires a bit more validation work than the
> simple straigh forward conversions.
> 

Applied with tweaks as mentioned in replies to individual patches.

Thanks,

Jonathan

> Lars-Peter Clausen (13):
>   iio: core: Use sysfs_emit()
>   iio: dmaengine-buffer: Use sysfs_emit()
>   iio: ad7192: Use sysfs_emit()
>   iio: ad9523: Use sysfs_emit()
>   iio: as3935: Use sysfs_emit()
>   iio: ina2xx-adc: sysfs_emit()
>   iio: lm3533: Use sysfs_emit()
>   iio: max31856: Use sysfs_emit()
>   iio: max31865: Use sysfs_emit()
>   iio: max9611: Use sysfs_emit()
>   iio: ms_sensors: Use sysfs_emit()
>   iio: scd4x: Use sysfs_emit()
>   iio: sps30: Use sysfs_emit()
> 
>  drivers/iio/adc/ad7192.c                           | 4 ++--
>  drivers/iio/adc/ina2xx-adc.c                       | 2 +-
>  drivers/iio/adc/max9611.c                          | 2 +-
>  drivers/iio/buffer/industrialio-buffer-dmaengine.c | 2 +-
>  drivers/iio/chemical/scd4x.c                       | 2 +-
>  drivers/iio/chemical/sps30.c                       | 2 +-
>  drivers/iio/common/ms_sensors/ms_sensors_i2c.c     | 4 ++--
>  drivers/iio/frequency/ad9523.c                     | 2 +-
>  drivers/iio/industrialio-buffer.c                  | 4 ++--
>  drivers/iio/industrialio-core.c                    | 2 +-
>  drivers/iio/light/lm3533-als.c                     | 6 +++---
>  drivers/iio/proximity/as3935.c                     | 4 ++--
>  drivers/iio/temperature/max31856.c                 | 4 ++--
>  drivers/iio/temperature/max31865.c                 | 4 ++--
>  14 files changed, 22 insertions(+), 22 deletions(-)
> 


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

end of thread, other threads:[~2022-01-16 16:48 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-16 18:52 [PATCH 00/13] iio: Use sysfs_emit() Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 01/13] iio: core: " Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 02/13] iio: dmaengine-buffer: " Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 03/13] iio: ad7192: " Lars-Peter Clausen
2021-12-23 13:30   ` Jonathan Cameron
2021-12-16 18:52 ` [PATCH 04/13] iio: ad9523: " Lars-Peter Clausen
2021-12-23 13:32   ` Jonathan Cameron
2021-12-16 18:52 ` [PATCH 05/13] iio: as3935: " Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 06/13] iio: ina2xx-adc: sysfs_emit() Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 07/13] iio: lm3533: Use sysfs_emit() Lars-Peter Clausen
2021-12-17  9:14   ` Johan Hovold
2022-01-16 16:50     ` Jonathan Cameron
2021-12-16 18:52 ` [PATCH 08/13] iio: max31856: " Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 09/13] iio: max31865: " Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 10/13] iio: max9611: " Lars-Peter Clausen
2021-12-17  9:05   ` Jacopo Mondi
2021-12-17  9:17     ` Lars-Peter Clausen
2021-12-17 10:09       ` Jacopo Mondi
2021-12-16 18:52 ` [PATCH 11/13] iio: ms_sensors: " Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 12/13] iio: scd4x: " Lars-Peter Clausen
2021-12-16 18:52 ` [PATCH 13/13] iio: sps30: " Lars-Peter Clausen
2022-01-16 16:54 ` [PATCH 00/13] iio: " Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.