hwmon: Replace sprintf() with sysfs_emit()
cover hwmon: Replace sprintf() with sysfs_emit()
This series of commits replaces sprintf() with sysfs_emit() in the code for several drivers (tc74, max31722, ads7828, max6659, emc1403) and helps avoid potential buffer overflows.
Amay Agarwal (5):
hwmon: tc74: use sysfs_emit() instead of sprintf()
hwmon: max31722: use sysfs_emit() instead of sprintf()
hwmon: ads7828: use sysfs_emit() instead of sprintf()
hwmon: max6650: use sysfs_emit() instead of sprintf()
hwmon: emc1403: use sysfs_emit() instead of sprintf()
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(-)
Thank you,
Amay
PATCH 1/5 hwmon: tc74: use sysfs_emit() instead of sprintf()
Replacing sprintf() with sysfs_emit() for drivers/hwmon/tc74.c since it is the preferred helper for formatting sysfs outputs and preventing buffer overflows.
--- drivers/hwmon/tc74.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/tc74.c +1 -1
@@ -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
Guenter Roeck
maintainerRe: [PATCH 1/5] hwmon: tc74: use sysfs_emit() instead of sprintf()
Quoted 1 line · Amay Agarwal
Replacing
sprintf()withsysfs_emit()fordrivers/hwmon/tc74.csince it
That is not "imperative mood" as asked for inDocumentation/process/submitting-patches.rst.
While minor, I think it is especially important in patches like this one which do not make functional changes.
On top of that, mentioning the driver name in the commit description is pointless, and the subject fir hwmon patches should start with "hwmon: (driver) ..."
Guenter
Quoted 21 lines
is the preferred helper for formatting sysfs outputs and preventing buffer overflows.
Signed-off-by Amay Agarwal <[email protected]>--- drivers/hwmon/tc74.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hwmon/tc74.c +1
-1@@ -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);
PATCH 2/5 hwmon: max31722: use sysfs_emit() instead of sprintf()
In reply to Amay AgarwalReplacing sprintf() with sysfs_emit() for drivers/hwmon/max31722.c since it is the preferred helper for formatting sysfs outputs and preventing buffer overflows.
--- drivers/hwmon/max31722.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/max31722.c +2 -1
@@ -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
Guenter Roeck
maintainerRe: [PATCH 2/5] hwmon: max31722: use sysfs_emit() instead of sprintf()
Quoted 4 lines · Amay Agarwal
Replacing
sprintf()withsysfs_emit()fordrivers/hwmon/max31722.csince it is the preferred helper for formatting sysfs outputs and preventing buffer overflows.
Same comment as for the other patch.
Guenter
Quoted 26 lines
Signed-off-by Amay Agarwal <[email protected]>--- drivers/hwmon/max31722.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hwmon/max31722.c +2
-1@@ -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);
Guenter Roeck
maintainerQuoted 18 lines · Amay Agarwal
This series of commits replaces
sprintf()withsysfs_emit()in the code for several drivers (tc74, max31722, ads7828, max6659, emc1403) and helps avoid potential buffer overflows.Amay Agarwal (5):
hwmon: tc74: usesysfs_emit()instead ofsprintf()
hwmon: max31722: usesysfs_emit()instead ofsprintf()
hwmon: ads7828: usesysfs_emit()instead ofsprintf()
hwmon: max6650: usesysfs_emit()instead ofsprintf()
hwmon: emc1403: usesysfs_emit()instead ofsprintf()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(-)
Quoted 3 lines
Thank you,
Amay
I have not seen patches 3..5 yet, but I bet I am sure they have the same problem as the first two patches, so I won't separately comment on those.
Guenter