[PATCH 2/5] hwmon: max31722: use sysfs_emit() instead of sprintf()

Amay Agarwal posted 5 patches 8 hours ago
Only 2 patches received!
[PATCH 2/5] hwmon: max31722: use sysfs_emit() instead of sprintf()
Posted by Amay Agarwal 8 hours ago
Replacing sprintf() with sysfs_emit() for drivers/hwmon/max31722.c since
it is the preferred helper for formatting sysfs outputs and preventing
buffer overflows.

Signed-off-by: Amay Agarwal <tt@turingtested.xyz>
---
 drivers/hwmon/max31722.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/max31722.c b/drivers/hwmon/max31722.c
index 9a31ef388396..6c5c86c75c36 100644
--- a/drivers/hwmon/max31722.c
+++ b/drivers/hwmon/max31722.c
@@ -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);
-- 
2.53.0
Re: [PATCH 2/5] hwmon: max31722: use sysfs_emit() instead of sprintf()
Posted by Guenter Roeck 6 hours ago
On Tue, Mar 03, 2026 at 12:58:13AM +0530, Amay Agarwal wrote:
> Replacing sprintf() with sysfs_emit() for drivers/hwmon/max31722.c since
> it is the preferred helper for formatting sysfs outputs and preventing
> buffer overflows.
> 
Same comment as for the other patch.

Guenter

> Signed-off-by: Amay Agarwal <tt@turingtested.xyz>
> ---
>  drivers/hwmon/max31722.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/max31722.c b/drivers/hwmon/max31722.c
> index 9a31ef388396..6c5c86c75c36 100644
> --- a/drivers/hwmon/max31722.c
> +++ b/drivers/hwmon/max31722.c
> @@ -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);