Skip to contentSkip to conversation

hwmon: Replace sprintf() with sysfs_emit()

PATCH Applied Amay Agarwal 2 participants 11 messages Mar 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover hwmon: Replace sprintf() with sysfs_emit()

This series replaces sprintf() with sysfs_emit() in several hwmon drivers when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional changes intended.

Changes in v2:

1. Use imperative mood in commit messages

2. Format subjects as "hwmon: (driver) ..."

3. Remove redundant driver name from commit descriptions

Amay Agarwal (5):
hwmon: (tc74) Replace sprintf() with sysfs_emit()
hwmon: (max31722) Replace sprintf() with sysfs_emit()
hwmon: (ads7828) Replace sprintf() with sysfs_emit()
hwmon: (max6650) Replace sprintf() with sysfs_emit()
hwmon: (emc1403) Replace sprintf() with sysfs_emit()

 drivers/hwmon/ads7828.c  | 2 +-
 drivers/hwmon/emc1403.c  | 2 +-
 drivers/hwmon/max31722.c | 3 ++-
 drivers/hwmon/max6650.c  | 3 ++-
 drivers/hwmon/tc74.c     | 2 +-
 5 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/5 hwmon: (tc74) Replace sprintf() with sysfs_emit()

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended

---
 drivers/hwmon/tc74.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/tc74.c +1 -1
index 9984373a25fb..7fb7b50ad1ad 100644
@@ -92,7 +92,7 @@ static ssize_t temp_input_show(struct device *dev,
 	if (ret)
 		return ret;
 
-	return sprintf(buf, "%d\n", data->temp_input * 1000);
+	return sysfs_emit(buf, "%d\n", data->temp_input * 1000);
 }
 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0);
 
Signature · 1 line
2.53.0
maintainer Applied
#2 lore raw

Re: [PATCH v2 1/5] hwmon: (tc74) Replace sprintf() with sysfs_emit()

Quoted 8 lines · Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended

Applied.

Thanks,
Guenter

#3 lore raw

PATCH v2 2/5 hwmon: (max31722) Replace sprintf() with sysfs_emit()

In reply to Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

---
 drivers/hwmon/max31722.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/max31722.c +2 -1
index 9a31ef388396..6c5c86c75c36 100644
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/spi/spi.h>
+#include <linux/sysfs.h>
 
 #define MAX31722_REG_CFG				0x00
 #define MAX31722_REG_TEMP_LSB				0x01
@@ -56,7 +57,7 @@ static ssize_t max31722_temp_show(struct device *dev,
 	if (ret < 0)
 		return ret;
 	/* Keep 12 bits and multiply by the scale of 62.5 millidegrees/bit. */
-	return sprintf(buf, "%d\n", (s16)le16_to_cpu(ret) * 125 / 32);
+	return sysfs_emit(buf, "%d\n", (s16)le16_to_cpu(ret) * 125 / 32);
 }
 
 static SENSOR_DEVICE_ATTR_RO(temp1_input, max31722_temp, 0);
Signature · 1 line
2.53.0
maintainer Applied
#4 lore raw

Re: [PATCH v2 2/5] hwmon: (max31722) Replace sprintf() with sysfs_emit()

Quoted 8 lines · Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

Applied.

Thanks,
Guenter

#5 lore raw

PATCH v2 3/5 hwmon: (ads7828) Replace sprintf() with sysfs_emit()

In reply to Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

---
 drivers/hwmon/ads7828.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ads7828.c +1 -1
index 436637264056..a09de9d016ac 100644
@@ -62,7 +62,7 @@ static ssize_t ads7828_in_show(struct device *dev,
 	if (err < 0)
 		return err;
 
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       DIV_ROUND_CLOSEST(regval * data->lsb_resol, 1000));
 }
 
Signature · 1 line
2.53.0
maintainer Applied
#6 lore raw

Re: [PATCH v2 3/5] hwmon: (ads7828) Replace sprintf() with sysfs_emit()

Quoted 8 lines · Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

Watch out for multip-line alignment issues in the future. No need to resend, I'll fix that.

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/ads7828.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ads7828.c +1 -1
index 436637264056..a09de9d016ac 100644
@@ -62,7 +62,7 @@ static ssize_t ads7828_in_show(struct device *dev,
 	if (err < 0)
 		return err;
 
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       DIV_ROUND_CLOSEST(regval * data->lsb_resol, 1000));
 }
 
#7 lore raw

PATCH v2 4/5 hwmon: (max6650) Replace sprintf() with sysfs_emit()

In reply to Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

---
 drivers/hwmon/max6650.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/max6650.c +2 -1
index 9649c6611d5f..56b8157885bb 100644
@@ -27,6 +27,7 @@
 #include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/sysfs.h>
 #include <linux/thermal.h>
 
 /*
@@ -312,7 +313,7 @@ static ssize_t alarm_show(struct device *dev,
 		mutex_unlock(&data->update_lock);
 	}
 
-	return sprintf(buf, "%d\n", alarm);
+	return sysfs_emit(buf, "%d\n", alarm);
 }
 
 static SENSOR_DEVICE_ATTR_RO(gpio1_alarm, alarm, MAX6650_ALRM_GPIO1);
Signature · 1 line
2.53.0
maintainer Applied
#8 lore raw

Re: [PATCH v2 4/5] hwmon: (max6650) Replace sprintf() with sysfs_emit()

Quoted 8 lines · Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

Applied.

Thanks,
Guenter

#9 lore raw

PATCH v2 5/5 hwmon: (emc1403) Replace sprintf() with sysfs_emit()

In reply to Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

---
 drivers/hwmon/emc1403.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/emc1403.c +1 -1
index ccce948a4306..964a8cb278f1 100644
@@ -40,7 +40,7 @@ static ssize_t power_state_show(struct device *dev, struct device_attribute *att
 	retval = regmap_read(data->regmap, 0x03, &val);
 	if (retval < 0)
 		return retval;
-	return sprintf(buf, "%d\n", !!(val & BIT(6)));
+	return sysfs_emit(buf, "%d\n", !!(val & BIT(6)));
 }
 
 static ssize_t power_state_store(struct device *dev, struct device_attribute *attr,
Signature · 1 line
2.53.0
maintainer Applied
#10 lore raw

Re: [PATCH v2 5/5] hwmon: (emc1403) Replace sprintf() with sysfs_emit()

Quoted 8 lines · Amay Agarwal

Replace sprintf() with sysfs_emit() when writing to sysfs buffers.

sysfs_emit() performs proper bounds checking and is the preferred helper for sysfs output.

No functional change intended.

Applied.

Thanks,
Guenter