iio: Use sysfs_emit()
Subsystems (5)
cover iio: Use sysfs_emit()
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(-)
Signature · 1 line
2.30.2
PATCH 1/13 iio: core: Use sysfs_emit()
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)").
--- drivers/iio/industrialio-buffer.c | 4 ++-- drivers/iio/industrialio-core.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/iio/industrialio-buffer.c +2 -2
@@ -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 ; }
drivers/iio/industrialio-core.c +1 -1
@@ -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 ; }
Signature · 1 line
2.30.2
PATCH 2/13 iio: dmaengine-buffer: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/buffer/industrialio-buffer-dmaengine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/buffer/industrialio-buffer-dmaengine.c +1 -1
@@ -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,
Signature · 1 line
2.30.2
PATCH 3/13 iio: ad7192: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/adc/ad7192.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7192.c +2 -2
@@ -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,
Signature · 1 line
2.30.2
Jonathan Cameron
maintainerRe: [PATCH 03/13] iio: ad7192: Use sysfs_emit()
Quoted 5 lines · On Thu, 16 Dec 2021 19:52:07 +0100 Lars-Peter Clausen <[email protected]> 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 customac_excicationandbridge_swtich
excitation
I'll fix up whilst applying if this doesn't need a respin for other reasons.
Quoted 29 lines
attributes of the ad7192 driver.
Signed-off-by Lars-Peter Clausen <[email protected]>--- drivers/iio/adc/ad7192.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iio/adc/ad7192.c +2
-2@@ -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,
PATCH 4/13 iio: ad9523: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/frequency/ad9523.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/frequency/ad9523.c +1 -1
@@ -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);
Signature · 1 line
2.30.2
Jonathan Cameron
maintainerRe: [PATCH 04/13] iio: ad9523: Use sysfs_emit()
Quoted 17 lines · On Thu, 16 Dec 2021 19:52:08 +0100 Lars-Peter Clausen <[email protected]> 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 <[email protected]>--- drivers/iio/frequency/ad9523.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/frequency/ad9523.c +0
-0
drivers/iio/frequency/ad9523.c static ssize_t ad9523_show(struct device *dev, · line 555
Quoted 6 lines
drivers/iio/frequency/ad9523.c +1
-1@@ -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.
Quoted 2 lines
drivers/iio/frequency/ad9523.c +0
-0}mutex_unlock (&st->lock);
PATCH 5/13 iio: as3935: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/proximity/as3935.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/proximity/as3935.c +2 -2
@@ -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;
Signature · 1 line
2.30.2
PATCH 6/13 iio: ina2xx-adc: sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/adc/ina2xx-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ina2xx-adc.c +1 -1
@@ -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,
Signature · 1 line
2.30.2
PATCH 7/13 iio: lm3533: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/light/lm3533-als.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/light/lm3533-als.c +3 -3
@@ -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,
Signature · 1 line
2.30.2
Re: [PATCH 07/13] iio: lm3533: Use sysfs_emit()
Quoted 3 lines · 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.
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).
Quoted 4 lines
Use
sysfs_emit()to format the custom device attributes of the lm3533 driver.Signed-off-by Lars-Peter Clausen <[email protected]>
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:
Quoted 27 lines
--- drivers/iio/light/lm3533-als.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/light/lm3533-als.c +2
-2@@ -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 {
drivers/iio/light/lm3533-als.c static ssize_t show_als_attr(struct device *dev, · line 536
Quoted 8 lines
drivers/iio/light/lm3533-als.c +1
-1@@ -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
Jonathan Cameron
maintainerRe: [PATCH 07/13] iio: lm3533: Use sysfs_emit()
Quoted 5 lines · On Fri, 17 Dec 2021 10:14:49 +0100 Johan Hovold <[email protected]> wrote:
Quoted 3 lines · 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.
Quoted 9 lines
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 aPAGE_SIZEargument.This should probably be rephrased in terms of consistency and the documentation now claiming that only
sysfs_emit()should be used inshow()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.
Quoted 7 lines
Quoted 4 lines
Use
sysfs_emit()to format the custom device attributes of the lm3533 driver.Signed-off-by Lars-Peter Clausen <[email protected]>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.
Quoted 2 lines
Reviewed-by Johan Hovold <[email protected]>
Thanks,
Jonathan
Quoted 38 lines
Quoted 28 lines
--- drivers/iio/light/lm3533-als.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/light/lm3533-als.c +2
-2@@ -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 {drivers/iio/light/lm3533-als.c static ssize_t show_als_attr(struct device *dev, · line 536
Quoted 8 lines
drivers/iio/light/lm3533-als.c +1
-1@@ -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
PATCH 8/13 iio: max31856: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/temperature/max31856.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/temperature/max31856.c +2 -2
@@ -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,
Signature · 1 line
2.30.2
PATCH 9/13 iio: max31865: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/temperature/max31865.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/temperature/max31865.c +2 -2
@@ -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,
Signature · 1 line
2.30.2
PATCH 10/13 iio: max9611: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/adc/max9611.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/max9611.c +1 -1
@@ -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,
Signature · 1 line
2.30.2
Re: [PATCH 10/13] iio: max9611: Use sysfs_emit()
Hi Lars-Peter,
Quoted 8 lines · 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 customin_power_shunt_resistorandin_current_shunt_resistordevice attributes of the max9611 driver.Signed-off-by Lars-Peter Clausen <[email protected]>
Looks good, I just wonder if a dependency on the CONFIG_SYSFS symbol should now be added...
Thanks
j
Quoted 20 lines
--- drivers/iio/adc/max9611.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/max9611.c +1
-2@@ -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
Re: [PATCH 10/13] iio: max9611: Use sysfs_emit()
Quoted 7 lines · Jacopo Mondi
Hi Lars-Peter,
Quoted 4 lines · 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.
Quoted 7 lines
Quoted 4 lines
Use
sysfs_emit()to format the customin_power_shunt_resistorandin_current_shunt_resistordevice attributes of the max9611 driver.Signed-off-by Lars-Peter Clausen <[email protected]>Looks good, I just wonder if a dependency on the
CONFIG_SYSFSsymbol 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.
Jacopo Mondi
Reviewed-byRe: [PATCH 10/13] iio: max9611: Use sysfs_emit()
Quoted 11 lines · Lars-Peter Clausen
Quoted 10 lines · Jacopo Mondi
Hi Lars-Peter,
Quoted 7 lines · 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 customin_power_shunt_resistorandin_current_shunt_resistordevice attributes of the max9611 driver.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Lars-Peter Clausen <[email protected]>Looks good, I just wonder if a dependency on the
CONFIG_SYSFSsymbol 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 :)
Thanks!
j
PATCH 11/13 iio: ms_sensors: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/common/ms_sensors/ms_sensors_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +2 -2
@@ -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);
Signature · 1 line
2.30.2
PATCH 12/13 iio: scd4x: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/chemical/scd4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/scd4x.c +1 -1
@@ -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,
Signature · 1 line
2.30.2
PATCH 13/13 iio: sps30: Use sysfs_emit()
In reply to Lars-Peter Clausensysfs_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.
--- drivers/iio/chemical/sps30.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30.c +1 -1
@@ -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,
Signature · 1 line
2.30.2
Jonathan Cameron
maintainerQuoted 4 lines · On Thu, 16 Dec 2021 19:52:04 +0100 Lars-Peter Clausen <[email protected]> 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.
Quoted 8 lines
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 useiio_read_raworiio_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
Quoted 31 lines
Lars-Peter Clausen (13):
iio: core: Usesysfs_emit()
iio: dmaengine-buffer: Usesysfs_emit()
iio: ad7192: Usesysfs_emit()
iio: ad9523: Usesysfs_emit()
iio: as3935: Usesysfs_emit()
iio: ina2xx-adc:sysfs_emit()
iio: lm3533: Usesysfs_emit()
iio: max31856: Usesysfs_emit()
iio: max31865: Usesysfs_emit()
iio: max9611: Usesysfs_emit()
iio:ms_sensors: Usesysfs_emit()
iio: scd4x: Usesysfs_emit()
iio: sps30: Usesysfs_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(-)