Skip to contentSkip to conversation

iio: replace sprintf() with sysfs_emit() in .read_label() op

PATCH In review Nuno Sá 4 participants 13 messages Sep 30, 2025 – Oct 4, 2025

Subsystems (10)
lore
Share & tools
lore

Nuno Sá

author maintainer
#0 lore raw

cover 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á

author maintainer
#1 lore raw

PATCH 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
index 1bc2f9a2247081e166680232aa6d4aebc5f41b89..4393160c7c77981729d8e43bbf1aa573616e4d40 100644
@@ -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
author maintainer
#2 lore raw

PATCH 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
index 872c88d0c86cab9f083e38dbc65463676c62001f..d96802b7847a6320c12fd121b0999256f3bd04a8 100644
@@ -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
author maintainer
#3 lore raw

PATCH 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
index cd679ff10a97c4be19ca461126bdfae2fa8431f2..fcdf13f49c48f31ba3a0a9079686d2b81a792744 100644
@@ -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
maintainer Reviewed-by on v1 3/9
#4 lore raw

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 use sysfs_emit() for generating labels.

---
 drivers/iio/adc/mcp3564.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mcp3564.c +0 -0

index cd679ff10a97c4be19ca461126bdfae2fa8431f2..fcdf13f49c48f31ba3a0a907968 6d2b81a792744 100644

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)

--
2.51.0

author maintainer
#5 lore raw

PATCH 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
index f7e7172ef4f6c2042f9ad54583d399f477ef7f5d..47cd350498a0d42536445ab324cc9249966b37d0 100644
@@ -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
author maintainer
#6 lore raw

PATCH 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
index 69b3569c90e5b665e1d2c59621df00d6142fbe9c..e0e4df418612469bb11a88bdbeb77aeb7cb833eb 100644
@@ -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
author maintainer
#7 lore raw

PATCH 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
index 35433250b00872edfc9214c632917a8b8ae6e281..a0227b57f23883034f84ac2ada3d4f9319e5047d 100644
@@ -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
author maintainer
#8 lore raw

PATCH 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
index f61ad0510f04c7760d3735020b5de854b0e31702..b245416bae12121e16033f0185d8d0d2ef28f7ee 100644
@@ -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
author maintainer
#9 lore raw

PATCH 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
index bff7039690ac33bcc9747add8055023dd5a1f3ab..a26d391661fdb64cc34c8c0e163333c01c1f069b 100644
@@ -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
maintainer Acked-by on v1 8/9
#10 lore raw

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 use sysfs_emit() for generating
labels.

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 -0

index bff7039690ac33bcc9747add8055023dd5a1f3ab..a26d391661fdb64cc34c8c0e163 333c01c1f069b 100644

drivers/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 struct iio_info hinge_info = {

author maintainer
#11 lore raw

PATCH 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
index 9b028c8bb1db142e2afd743aa3ace1d6d3230ae5..06d9c784f93e01288b42a1b9aee36b9f84e4b7f4 100644
@@ -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
maintainer
#12 lore raw
In reply to Nuno Sá
Quoted 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 even snprintf() with PAGE_SIZE) instead of sysfs_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: 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á