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

Amay Agarwal posted 5 patches 1 month ago
[PATCH v2 3/5] hwmon: (ads7828) Replace sprintf() with sysfs_emit()
Posted by Amay Agarwal 1 month ago
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.

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

diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index 436637264056..a09de9d016ac 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -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));
 }
 
-- 
2.53.0
Re: [PATCH v2 3/5] hwmon: (ads7828) Replace sprintf() with sysfs_emit()
Posted by Guenter Roeck 1 month ago
On Tue, Mar 03, 2026 at 08:54:54PM +0530, Amay Agarwal wrote:
> 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.
> 
> Signed-off-by: Amay Agarwal <tt@turingtested.xyz>

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

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/ads7828.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
> index 436637264056..a09de9d016ac 100644
> --- a/drivers/hwmon/ads7828.c
> +++ b/drivers/hwmon/ads7828.c
> @@ -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));
>  }
>