iio: cros_ec: use sysfs_emit() in show callbacks
Subsystems (2)
PATCH 1/1 iio: cros_ec: use sysfs_emit() in show callbacks
Replace sprintf() and snprintf() with sysfs_emit() in the sysfs show and ext_info read callbacks. sysfs_emit() is aware of the sysfs buffer PAGE_SIZE limit and is the preferred helper for show callbacks.
--- .../iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +5 -5
@@ -149,9 +149,9 @@ static ssize_t cros_ec_sensor_get_report_latency(struct device *dev,if (ret <0 )return ret; -return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 ); } static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,
@@ -165,7 +165,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev,struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); -return sprintf (buf,"%d\n" , st->fifo_max_event_count); +return sysfs_emit (buf,"%d\n" , st->fifo_max_event_count); } static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
@@ -465,7 +465,7 @@ static ssize_t cros_ec_sensors_id(struct iio_dev *indio_dev, {struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); -return snprintf (buf,PAGE_SIZE ,"%d\n" , st->param.info.sensor_num); +return sysfs_emit (buf,"%d\n" , st->param.info.sensor_num); }const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[] = {
base-commit: b70566610b48ba49dec636019da4d696db64b085
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
Quoted 5 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.Signed-off-by Di Wu <[email protected]>
Quoted 44 lines
--- .../iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +5
-5@@ -149,9 +149,9 @@ static ssize_t cros_ec_sensor_get_report_latency(struct device *dev,if (ret <0 )return ret; -return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 ); } static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,@@ -165,7 +165,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev,struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); -return sprintf (buf,"%d\n" , st->fifo_max_event_count); +return sysfs_emit (buf,"%d\n" , st->fifo_max_event_count); } static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);@@ -465,7 +465,7 @@ static ssize_t cros_ec_sensors_id(struct iio_dev *indio_dev, {struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); -return snprintf (buf,PAGE_SIZE ,"%d\n" , st->param.info.sensor_num); +return sysfs_emit (buf,"%d\n" , st->param.info.sensor_num); }const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[] = {base-commit:
b70566610b48ba49dec636019da4d696db64b085Signature · 1 line
2.56.0.455.g6c5a503b38-goog
Quoted 3 lines · On Wed, 11 Nov 2026 07:26:08 +0000 Di Wu <[email protected]> wrote:
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.
Quoted 11 lines
Signed-off-by Di Wu <[email protected]>--- .../iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +0
-0
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static ssize_t cros_ec_sensor_get_report_latency(struct device *dev, · line 154
Quoted 9 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-3@@ -149,9 +149,9 @@ static ssize_t cros_ec_sensor_get_report_latency(struct device *dev,if (ret <0 )return ret; -return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 );
At least two of those lines can be merged.
I think it is 86 chars - maybe ok.
Personally I'd split after the format.
David
Quoted 23 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2
-2} static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,@@ -165,7 +165,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev,struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); -return sprintf (buf,"%d\n" , st->fifo_max_event_count); +return sysfs_emit (buf,"%d\n" , st->fifo_max_event_count); } static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);@@ -465,7 +465,7 @@ static ssize_t cros_ec_sensors_id(struct iio_dev *indio_dev, {struct cros_ec_sensors_core_state *st =iio_priv (indio_dev); -return snprintf (buf,PAGE_SIZE ,"%d\n" , st->param.info.sensor_num); +return sysfs_emit (buf,"%d\n" , st->param.info.sensor_num); }const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[] = {base-commit:
b70566610b48ba49dec636019da4d696db64b085
Quoted 3 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.
...
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static ssize_t cros_ec_sensor_get_report_latency(struct device *dev, · line 154
Quoted 6 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-3-return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 );
As David said, since you touched these lines, make the less amount of them while at it.
(But no need to resend, usually Jonathan is kind to tweak this small thing.)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 19 lines · On Wed, 11 Nov 2026 16:39:37 +0200 Andy Shevchenko…
Quoted 3 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.Reviewed-by Andy Shevchenko <[email protected]>...
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static ssize_t cros_ec_sensor_get_report_latency(struct device *dev, · line 154
Quoted 6 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-3-return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 );As David said, since you touched these lines, make the less amount of them while at it.
Quoted 2 lines
(But no need to resend, usually Jonathan is kind to tweak this small thing.)
Done and applied.
Quoted 22 lines · On Thu, 12 Nov 2026 02:04:39 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 19 lines · On Wed, 11 Nov 2026 16:39:37 +0200 Andy Shevchenko…
Quoted 3 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.Reviewed-by Andy Shevchenko <[email protected]>...
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static ssize_t cros_ec_sensor_get_report_latency(struct device *dev, · line 154
Quoted 6 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-3-return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 );As David said, since you touched these lines, make the less amount of them while at it.
Quoted 5 lines
Quoted 2 lines
(But no need to resend, usually Jonathan is kind to tweak this small thing.)
Done and applied.
I just looked at that line again.
Why is it multiplying the remainder by 1000?
It could be:
return sysfs_emit(buf, "%d.%03u000\n", latency / 1000, latency % 1000);
if the 6 digits after the decimal point are required.
David
Jonathan Cameron
maintainerQuoted 31 lines · On Thu, 12 Nov 2026 22:02:18 +0000 David Laight <[email protected]>…
Quoted 22 lines · On Thu, 12 Nov 2026 02:04:39 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 19 lines · On Wed, 11 Nov 2026 16:39:37 +0200 Andy Shevchenko…
Quoted 3 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.Reviewed-by Andy Shevchenko <[email protected]>...
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static ssize_t cros_ec_sensor_get_report_latency(struct device *dev, · line 154
Quoted 6 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-3-return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 );As David said, since you touched these lines, make the less amount of them while at it.
Quoted 5 lines
Quoted 2 lines
(But no need to resend, usually Jonathan is kind to tweak this small thing.)
Done and applied.
Quoted 5 lines
I just looked at that line again.
Why is it multiplying the remainder by 1000?
It could be:return sysfs_emit(buf, "%d.%03u000\n", latency / 1000, latency % 1000);if the 6 digits after the decimal point are required.
Good point, I guess unrelated change that we could have on top. Those trailing zeros shouldn't matter.
Quoted 2 lines
David
Quoted 34 lines · On Fri, 13 Nov 2026 01:36:46 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 31 lines · On Thu, 12 Nov 2026 22:02:18 +0000 David Laight <[email protected]>…
Quoted 27 lines · On Thu, 12 Nov 2026 02:04:39 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 19 lines · On Wed, 11 Nov 2026 16:39:37 +0200 Andy Shevchenko…
Quoted 3 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.Reviewed-by Andy Shevchenko <[email protected]>...
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static ssize_t cros_ec_sensor_get_report_latency(struct device *dev, · line 154
Quoted 6 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-3-return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 );As David said, since you touched these lines, make the less amount of them while at it.
Quoted 2 lines
(But no need to resend, usually Jonathan is kind to tweak this small thing.)
Done and applied.
Quoted 7 lines
Quoted 5 lines
I just looked at that line again.
Why is it multiplying the remainder by 1000?
It could be:return sysfs_emit(buf, "%d.%03u000\n", latency / 1000, latency % 1000);if the 6 digits after the decimal point are required.
Good point, I guess unrelated change that we could have on top.
Indeed.
Quoted 1 line
Those trailing zeros shouldn't matter.
There is a matching oddity in the set function (just above). It calls iio_str_to_fixpoint(buf, 1000000, &integer, &fract) then does latency = integer * 1000 + fract/1000. Just replace the 100000 by 1000 and you don't need the divide.
iio_str_to_fixpoint() will ignore are extra fractional digits.
Although I'm not at all sure its handling of negative value is correct. It converts -1.5 to -1/5 and -0.5 to 0/-5.
I can't see how that is useful since i*10+f for both gives -5.
I'd have though that either the fractional part should always be positive so -1.4 would need converting to -2/6 or it would have the same sign as the integer part and -1.4 would be converted to -1/-4.
David
Quoted 4 lines
Quoted 3 lines
David
Jonathan Cameron
maintainerQuoted 56 lines · On Fri, 13 Nov 2026 09:23:05 +0000 David Laight <[email protected]>…
Quoted 34 lines · On Fri, 13 Nov 2026 01:36:46 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 31 lines · On Thu, 12 Nov 2026 22:02:18 +0000 David Laight <[email protected]>…
Quoted 27 lines · On Thu, 12 Nov 2026 02:04:39 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 19 lines · On Wed, 11 Nov 2026 16:39:37 +0200 Andy Shevchenko…
Quoted 3 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.Reviewed-by Andy Shevchenko <[email protected]>...
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c static ssize_t cros_ec_sensor_get_report_latency(struct device *dev, · line 154
Quoted 6 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3
-3-return sprintf (buf,"%d.%06u\n" , - latency /1000 , - (latency %1000 ) *1000 ); +return sysfs_emit (buf,"%d.%06u\n" , + latency /1000 , + (latency %1000 ) *1000 );As David said, since you touched these lines, make the less amount of them while at it.
Quoted 2 lines
(But no need to resend, usually Jonathan is kind to tweak this small thing.)
Done and applied.
Quoted 7 lines
Quoted 5 lines
I just looked at that line again.
Why is it multiplying the remainder by 1000?
It could be:return sysfs_emit(buf, "%d.%03u000\n", latency / 1000, latency % 1000);if the 6 digits after the decimal point are required.
Good point, I guess unrelated change that we could have on top.
Indeed.
Quoted 1 line
Those trailing zeros shouldn't matter.
There is a matching oddity in the set function (just above). It calls
iio_str_to_fixpoint(buf, 1000000, &integer, &fract)then does latency = integer * 1000 + fract/1000. Just replace the 100000 by 1000 and you don't need the divide.
iio_str_to_fixpoint()will ignore are extra fractional digits.
Quoted 7 lines
Although I'm not at all sure its handling of negative value is correct. It converts -1.5 to -1/5 and -0.5 to 0/-5.
I can't see how that is useful since i*10+f for both gives -5.I'd have though that either the fractional part should always be positive so -1.4 would need converting to -2/6 or it would have the same sign as the integer part and -1.4 would be converted to -1/-4.
That is rather odd use of the output of iio_str_to_fixpoint() which admittedly is a bit unusual because of the need to handle there being no where to put that negative when the integer is 0.
Can get away with it here though as latencies aren't negative so. The code doesn't seem to actually check that though which might be a nice useability improvement rather than setting it to something odd.
Jonathan
Quoted 8 lines
David
Quoted 4 lines
Quoted 3 lines
David
Quoted 67 lines · On Sat, 14 Nov 2026 02:15:54 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 56 lines · On Fri, 13 Nov 2026 09:23:05 +0000 David Laight <[email protected]>…
Quoted 34 lines · On Fri, 13 Nov 2026 01:36:46 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 31 lines · On Thu, 12 Nov 2026 22:02:18 +0000 David Laight <[email protected]>…
Quoted 27 lines · On Thu, 12 Nov 2026 02:04:39 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 19 lines · On Wed, 11 Nov 2026 16:39:37 +0200 Andy Shevchenko…
Quoted 3 lines · Di Wu
Replace
sprintf()andsnprintf()withsysfs_emit()in the sysfs show andext_inforead callbacks.sysfs_emit()is aware of the sysfs bufferPAGE_SIZElimit and is the preferred helper for show callbacks.Reviewed-by Andy Shevchenko <[email protected]>...
Review
Quoted 6 lines
(quoted diff) +3
-3- return sprintf(buf, "%d.%06u\n", - latency / 1000, - (latency % 1000) * 1000); + return sysfs_emit(buf, "%d.%06u\n", + latency / 1000, + (latency % 1000) * 1000);As David said, since you touched these lines, make the less amount of them while at it.
Quoted 2 lines
(But no need to resend, usually Jonathan is kind to tweak this small thing.)
Done and applied.
Quoted 7 lines
Quoted 5 lines
I just looked at that line again.
Why is it multiplying the remainder by 1000?
It could be:return sysfs_emit(buf, "%d.%03u000\n", latency / 1000, latency % 1000);if the 6 digits after the decimal point are required.
Good point, I guess unrelated change that we could have on top.
Indeed.
Quoted 1 line
Those trailing zeros shouldn't matter.
There is a matching oddity in the set function (just above). It calls
iio_str_to_fixpoint(buf, 1000000, &integer, &fract)then does latency = integer * 1000 + fract/1000. Just replace the 100000 by 1000 and you don't need the divide.
iio_str_to_fixpoint()will ignore are extra fractional digits.Quoted 7 lines
Although I'm not at all sure its handling of negative value is correct. It converts -1.5 to -1/5 and -0.5 to 0/-5.
I can't see how that is useful since i*10+f for both gives -5.I'd have though that either the fractional part should always be positive so -1.4 would need converting to -2/6 or it would have the same sign as the integer part and -1.4 would be converted to -1/-4.
Quoted 7 lines
That is rather odd use of the output of
iio_str_to_fixpoint()which admittedly is a bit unusual because of the need to handle there being no where to put that negative when the integer is 0.Can get away with it here though as latencies aren't negative so. The code doesn't seem to actually check that though which might be a nice useability improvement rather than setting it to something odd.
I did wonder if it is ever used for negative values.
I'd have thought that fixed point maths would always want a positive fraction, so needs (eg) val/1000 and val%1000 to truncate to -infinity whereas C divides truncate towards zero.
It is possible that the function should just convert 1.234 to 1234 and 1.2 to 1200 (assuming 1000 for the input parameter).
Clearly not really relevant here - apart from not erroring negatives.
David
Quoted 16 lines
Jonathan
Quoted 8 lines
David
Quoted 4 lines
Quoted 3 lines
David