iio: replace sprintf() with sysfs_emit() in .read_label() op
Subsystems (10)
Nuno Sá
maintainercover iio: replace sprintf() with sysfs_emit() in .read_label() op
When looking at some drivers implementing the .read_label() callback it came to my attention that there were some outliers using sprintf() (or even snprintf() with PAGE_SIZE) instead of sysfs_emit(). This series cleans that up.
---
Nuno Sá (9):
iio: adc: ad4030: replace sprintf() with sysfs_emit()
iio: adc: ad7768-1: replace sprintf() with sysfs_emit()
iio: adc: mcp3564: replace sprintf() with sysfs_emit()
iio: adc: meson_saradc: replace sprintf() with sysfs_emit()
iio: adc: mt6360-adc: replace snprintf() with sysfs_emit()
iio: adc: pac1921: replace sprintf() with sysfs_emit()
iio: adc: qcom-spmi-rradc: replace snprintf() with sysfs_emit()
iio: position: hid-sensor-custom-intel-hinge: replace sprintf() with sysfs_emit()
iio: resolver: ad2s1210: replace sprintf() with sysfs_emit()
drivers/iio/adc/ad4030.c | 4 +-- drivers/iio/adc/ad7768-1.c | 2 +- drivers/iio/adc/mcp3564.c | 2 +- drivers/iio/adc/meson_saradc.c | 6 ++--- drivers/iio/adc/mt6360-adc.c | 2 +- drivers/iio/adc/pac1921.c | 8 +++--- drivers/iio/adc/qcom-spmi-rradc.c | 2 +- .../iio/position/hid-sensor-custom-intel-hinge.c | 2 +- drivers/iio/resolver/ad2s1210.c | 30 +++++++++++----------- 9 files changed, 29 insertions(+), 29 deletions(-)
---
base-commit: b9700f87939f0f477e5c00db817f54ab8a97702b
change-id: 20250930-dev-sprintf-cleanup-baf2c89b3460 --
Thanks!
- Nuno Sá
Nuno Sá
maintainerPATCH 1/9 iio: adc: ad4030: replace sprintf() with sysfs_emit()
Update the ad4030_read_label() function to use sysfs_emit() for generating labels.
--- drivers/iio/adc/ad4030.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad4030.c +2 -2
@@ -852,8 +852,8 @@ static int ad4030_read_label(struct iio_dev *indio_dev, char *label) {if (chan->differential) -return sprintf (label,"differential%lu\n" , chan->address); -return sprintf (label,"common-mode%lu\n" , chan->address); +return sysfs_emit (label,"differential%lu\n" , chan->address); +return sysfs_emit (label,"common-mode%lu\n" , chan->address); } static int ad4030_get_current_scan_type(const struct iio_dev *indio_dev,
Signature · 1 line
2.51.0
Nuno Sá
maintainerPATCH 2/9 iio: adc: ad7768-1: replace sprintf() with sysfs_emit()
In reply to Nuno SáUpdate the ad7768_read_label() function to use sysfs_emit(() for generating labels.
--- drivers/iio/adc/ad7768-1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7768-1.c +1 -1
@@ -899,7 +899,7 @@ static int ad7768_read_label(struct iio_dev *indio_dev, {struct ad7768_state *st =iio_priv (indio_dev); -return sprintf (label,"%s\n" , st->labels[chan->channel]); +return sysfs_emit (label,"%s\n" , st->labels[chan->channel]); } static int ad7768_get_current_scan_type(const struct iio_dev *indio_dev,
Signature · 1 line
2.51.0
Nuno Sá
maintainerPATCH 3/9 iio: adc: mcp3564: replace sprintf() with sysfs_emit()
In reply to Nuno SáUpdate the mcp3564_read_label() function to use sysfs_emit() for generating labels.
--- drivers/iio/adc/mcp3564.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mcp3564.c +1 -1
@@ -987,7 +987,7 @@ static int mcp3564_read_label(struct iio_dev *indio_dev, {struct mcp3564_state *adc =iio_priv (indio_dev); -return sprintf (label,"%s\n" , adc->labels[chan->scan_index]); +return sysfs_emit (label,"%s\n" , adc->labels[chan->scan_index]); }static int mcp3564_parse_fw_children (struct iio_dev *indio_dev)
Signature · 1 line
2.51.0
Re: [PATCH 3/9] iio: adc: mcp3564: replace sprintf() with sysfs_emit()
Quoted 34 lines · On Tue, 2025-09-30 at 16:33 +0100, Nuno Sá via B4 Relay wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
From: Nuno Sá <[email protected]>
Update the
mcp3564_read_label()function to usesysfs_emit()for generating labels.Signed-off-by Nuno Sá <[email protected]>---
drivers/iio/adc/mcp3564.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/mcp3564.c +0
-0index
cd679ff10a97c4be19ca461126bdfae2fa8431f2..fcdf13f49c48f31ba3a0a9079686d2b81a792744100644drivers/iio/adc/mcp3564.c +1
-1@@ -987,7 +987,7 @@ static int mcp3564_read_label(struct iio_dev *indio_dev, { struct mcp3564_state *adc = iio_priv(indio_dev); - return sprintf(label, "%s\n", adc->labels[chan->scan_index]); + return sysfs_emit(label, "%s\n", adc->labels[chan- >scan_index]); }static int
mcp3564_parse_fw_children(struct iio_dev *indio_dev)--
2.51.0
Nuno Sá
maintainerPATCH 4/9 iio: adc: meson_saradc: replace sprintf() with sysfs_emit()
In reply to Nuno SáUpdate the read_label() function to use sysfs_emit() for generating labels.
--- drivers/iio/adc/meson_saradc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/meson_saradc.c +3 -3
@@ -1181,12 +1181,12 @@ static int read_label(struct iio_dev *indio_dev, char *label) {if (chan->type ==IIO_TEMP ) -return sprintf (label,"temp-sensor\n" ); +return sysfs_emit (label,"temp-sensor\n" );if (chan->type ==IIO_VOLTAGE && chan->channel >=NUM_MUX_0_VSS ) -return sprintf (label,"%s\n" , +return sysfs_emit (label,"%s\n" , chan7_mux_names[chan->channel -NUM_MUX_0_VSS ]);if (chan->type ==IIO_VOLTAGE ) -return sprintf (label,"channel-%d\n" , chan->channel); +return sysfs_emit (label,"channel-%d\n" , chan->channel);return 0 ; }
Signature · 1 line
2.51.0
Nuno Sá
maintainerPATCH 5/9 iio: adc: mt6360-adc: replace snprintf() with sysfs_emit()
In reply to Nuno SáUpdate the mt6360_adc_read_label() function to use sysfs_emit() for generating labels.
--- drivers/iio/adc/mt6360-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mt6360-adc.c +1 -1
@@ -216,7 +216,7 @@ static const char *mt6360_channel_labels[MT6360_CHAN_MAX] = {static int mt6360_adc_read_label (struct iio_dev *iio_dev,const struct iio_chan_spec *chan,char *label) { -return snprintf (label,PAGE_SIZE ,"%s\n" , mt6360_channel_labels[chan->channel]); +return sysfs_emit (label,"%s\n" , mt6360_channel_labels[chan->channel]); }static const struct iio_info mt6360_adc_iio_info = {
Signature · 1 line
2.51.0
Nuno Sá
maintainerPATCH 6/9 iio: adc: pac1921: replace sprintf() with sysfs_emit()
In reply to Nuno SáUpdate the pac1921_read_label() function to use sysfs_emit() for generating labels.
--- drivers/iio/adc/pac1921.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/adc/pac1921.c +4 -4
@@ -672,13 +672,13 @@ static int pac1921_read_label(struct iio_dev *indio_dev, {switch (chan->channel) {case PAC1921_CHAN_VBUS : -return sprintf (label,"vbus\n" ); +return sysfs_emit (label,"vbus\n" );case PAC1921_CHAN_VSENSE : -return sprintf (label,"vsense\n" ); +return sysfs_emit (label,"vsense\n" );case PAC1921_CHAN_CURRENT : -return sprintf (label,"current\n" ); +return sysfs_emit (label,"current\n" );case PAC1921_CHAN_POWER : -return sprintf (label,"power\n" ); +return sysfs_emit (label,"power\n" );default :return -EINVAL ; }
Signature · 1 line
2.51.0
Nuno Sá
maintainerPATCH 7/9 iio: adc: qcom-spmi-rradc: replace snprintf() with sysfs_emit()
In reply to Nuno SáUpdate the rradc_read_label() function to use sysfs_emit() for generating labels.
--- drivers/iio/adc/qcom-spmi-rradc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/qcom-spmi-rradc.c +1 -1
@@ -769,7 +769,7 @@ static int rradc_read_raw(struct iio_dev *indio_dev,static int rradc_read_label (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,char *label) { -return snprintf (label,PAGE_SIZE ,"%s\n" , +return sysfs_emit (label,"%s\n" , rradc_chans[chan->address].label); }
Signature · 1 line
2.51.0
Nuno Sá
maintainerPATCH 8/9 iio: position: hid-sensor-custom-intel-hinge: replace sprintf() with sysfs_emit()
In reply to Nuno SáUpdate the hinge_read_label() function to use sysfs_emit() for generating labels.
--- drivers/iio/position/hid-sensor-custom-intel-hinge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/position/hid-sensor-custom-intel-hinge.c +1 -1
@@ -176,7 +176,7 @@ static int hinge_read_label(struct iio_dev *indio_dev, {struct hinge_state *st =iio_priv (indio_dev); -return sprintf (label,"%s\n" , st->labels[chan->channel]); +return sysfs_emit (label,"%s\n" , st->labels[chan->channel]); }static const struct iio_info hinge_info = {
Signature · 1 line
2.51.0
Re: [PATCH 8/9] iio: position: hid-sensor-custom-intel-hinge: replace sprintf() with sysfs_emit()
Quoted 7 lines · On Tue, 2025-09-30 at 16:33 +0100, Nuno Sá via B4 Relay wrote:
From: Nuno Sá <[email protected]>
Update the
hinge_read_label()function to usesysfs_emit()for generating
labels.Signed-off-by Nuno Sá <[email protected]>
Quoted 21 lines
---
drivers/iio/position/hid-sensor-custom-intel-hinge.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/position/hid-sensor-custom-intel-hinge.c +0
-0index
bff7039690ac33bcc9747add8055023dd5a1f3ab..a26d391661fdb64cc34c8c0e163333c01c1f069b100644drivers/iio/position/hid-sensor-custom-intel-hinge.c +0
-0@@ -176,7 +176,7 @@ static int hinge_read_label(struct iio_dev *indio_dev, { struct hinge_state *st = iio_priv(indio_dev);drivers/iio/position/hid-sensor-custom-intel-hinge.c +1
-1-return sprintf (label,"%s\n" , st->labels[chan->channel]); +return sysfs_emit (label,"%s\n" , st->labels[chan->channel]);}
static const structiio_infohinge_info= {
Nuno Sá
maintainerPATCH 9/9 iio: resolver: ad2s1210: replace sprintf() with sysfs_emit()
In reply to Nuno SáUpdate the ad2s1210_read_label() and ad2s1210_read_event_label() functions to use sysfs_emit() for generating labels.
--- drivers/iio/resolver/ad2s1210.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/iio/resolver/ad2s1210.c +15 -15
@@ -1132,23 +1132,23 @@ static int ad2s1210_read_label(struct iio_dev *indio_dev, {if (chan->type ==IIO_ANGL ) {if (chan->channel ==0 ) -return sprintf (label,"position\n" ); +return sysfs_emit (label,"position\n" );if (chan->channel ==1 ) -return sprintf (label,"tracking error\n" ); +return sysfs_emit (label,"tracking error\n" ); }if (chan->type ==IIO_ANGL_VEL ) -return sprintf (label,"velocity\n" ); +return sysfs_emit (label,"velocity\n" );if (chan->type ==IIO_PHASE ) -return sprintf (label,"synthetic reference\n" ); +return sysfs_emit (label,"synthetic reference\n" );if (chan->type ==IIO_ALTVOLTAGE ) {if (chan->output) -return sprintf (label,"excitation\n" ); +return sysfs_emit (label,"excitation\n" );if (chan->channel ==0 ) -return sprintf (label,"monitor signal\n" ); +return sysfs_emit (label,"monitor signal\n" );if (chan->channel ==1 ) -return sprintf (label,"cosine\n" ); +return sysfs_emit (label,"cosine\n" );if (chan->channel ==2 ) -return sprintf (label,"sine\n" ); +return sysfs_emit (label,"sine\n" ); }return -EINVAL ;
@@ -1239,24 +1239,24 @@ static int ad2s1210_read_event_label(struct iio_dev *indio_dev, char *label) {if (chan->type ==IIO_ANGL ) -return sprintf (label,"LOT\n" ); +return sysfs_emit (label,"LOT\n" );if (chan->type ==IIO_ANGL_VEL ) -return sprintf (label,"max tracking rate\n" ); +return sysfs_emit (label,"max tracking rate\n" );if (chan->type ==IIO_PHASE ) -return sprintf (label,"phase lock\n" ); +return sysfs_emit (label,"phase lock\n" );if (chan->type ==IIO_ALTVOLTAGE ) {if (chan->channel ==0 ) {if (type ==IIO_EV_TYPE_THRESH && dir ==IIO_EV_DIR_FALLING ) -return sprintf (label,"LOS\n" ); +return sysfs_emit (label,"LOS\n" );if (type ==IIO_EV_TYPE_THRESH && dir ==IIO_EV_DIR_RISING ) -return sprintf (label,"DOS overrange\n" ); +return sysfs_emit (label,"DOS overrange\n" );if (type ==IIO_EV_TYPE_MAG ) -return sprintf (label,"DOS mismatch\n" ); +return sysfs_emit (label,"DOS mismatch\n" ); }if (chan->channel ==1 || chan->channel ==2 ) -return sprintf (label,"clipped\n" ); +return sysfs_emit (label,"clipped\n" ); }return -EINVAL ;
Signature · 1 line
2.51.0
Jonathan Cameron
maintainerQuoted 4 lines · On Tue, 30 Sep 2025 16:33:09 +0100 Nuno Sá via B4 Relay…
When looking at some drivers implementing the .read_label() callback it came to my attention that there were some outliers using
sprintf()(or evensnprintf()withPAGE_SIZE) instead ofsysfs_emit(). This series cleans that up.
I hope this doesn't come back to bite us by a future in kernel consumer not directly spitting the result of this into a sysfs read buffer. Anyhow today it's fine and we have existing cases doing sysfs_emit() so arguably any future problems aren't made worse by this patch set + for common usage it's an improvement.
So applied.
Thanks,
Jonathan
Quoted 32 lines
---
Nuno Sá (9):
iio: adc: ad4030: replacesprintf()withsysfs_emit()
iio: adc: ad7768-1: replacesprintf()withsysfs_emit()
iio: adc: mcp3564: replacesprintf()withsysfs_emit()
iio: adc:meson_saradc: replacesprintf()withsysfs_emit()
iio: adc: mt6360-adc: replacesnprintf()withsysfs_emit()
iio: adc: pac1921: replacesprintf()withsysfs_emit()
iio: adc: qcom-spmi-rradc: replacesnprintf()withsysfs_emit()
iio: position: hid-sensor-custom-intel-hinge: replacesprintf()withsysfs_emit()
iio: resolver: ad2s1210: replacesprintf()withsysfs_emit()drivers/iio/adc/ad4030.c | 4 +-- drivers/iio/adc/ad7768-1.c | 2 +- drivers/iio/adc/mcp3564.c | 2 +- drivers/iio/adc/meson_saradc.c | 6 ++--- drivers/iio/adc/mt6360-adc.c | 2 +- drivers/iio/adc/pac1921.c | 8 +++--- drivers/iio/adc/qcom-spmi-rradc.c | 2 +- .../iio/position/hid-sensor-custom-intel-hinge.c | 2 +- drivers/iio/resolver/ad2s1210.c | 30 +++++++++++----------- 9 files changed, 29 insertions(+), 29 deletions(-)---
base-commit:b9700f87939f0f477e5c00db817f54ab8a97702b
change-id: 20250930-dev-sprintf-cleanup-baf2c89b3460 --Thanks!
- Nuno Sá