diff mbox series

[2/5] hwmon: (dell-smm) Use strscpy_pad()

Message ID 20211021175447.5380-3-W_Armin@gmx.de (mailing list archive)
State Superseded
Headers show
Series hwmon: (dell-smm) Miscellaneous Improvments | expand

Commit Message

Armin Wolf Oct. 21, 2021, 5:54 p.m. UTC
From: Armin Wolf <W_Armin@gmx.de>

Using strscpy_pad() allows for fewer memory accesses
since memset() will not unconditionally zero-out
the whole buffer.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/hwmon/dell-smm-hwmon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.20.1

Comments

Pali Rohár Oct. 21, 2021, 6:17 p.m. UTC | #1
On Thursday 21 October 2021 19:54:44 W_Armin@gmx.de wrote:
> From: Armin Wolf <W_Armin@gmx.de>
> 
> Using strscpy_pad() allows for fewer memory accesses
> since memset() will not unconditionally zero-out
> the whole buffer.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>

Acked-by: Pali Rohár <pali@kernel.org>

> ---
>  drivers/hwmon/dell-smm-hwmon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
> index 9773d6c0477a..b0c591bb761a 100644
> --- a/drivers/hwmon/dell-smm-hwmon.c
> +++ b/drivers/hwmon/dell-smm-hwmon.c
> @@ -25,6 +25,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/proc_fs.h>
>  #include <linux/seq_file.h>
> +#include <linux/string.h>
>  #include <linux/smp.h>
>  #include <linux/types.h>
>  #include <linux/uaccess.h>
> @@ -472,8 +473,7 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
>  		if (restricted && !capable(CAP_SYS_ADMIN))
>  			return -EPERM;
> 
> -		memset(buff, 0, sizeof(buff));
> -		strscpy(buff, data->bios_machineid, sizeof(buff));
> +		strscpy_pad(buff, data->bios_machineid, sizeof(buff));
>  		break;
> 
>  	case I8K_FN_STATUS:
> --
> 2.20.1
>
diff mbox series

Patch

diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
index 9773d6c0477a..b0c591bb761a 100644
--- a/drivers/hwmon/dell-smm-hwmon.c
+++ b/drivers/hwmon/dell-smm-hwmon.c
@@ -25,6 +25,7 @@ 
 #include <linux/platform_device.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/string.h>
 #include <linux/smp.h>
 #include <linux/types.h>
 #include <linux/uaccess.h>
@@ -472,8 +473,7 @@  i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
 		if (restricted && !capable(CAP_SYS_ADMIN))
 			return -EPERM;

-		memset(buff, 0, sizeof(buff));
-		strscpy(buff, data->bios_machineid, sizeof(buff));
+		strscpy_pad(buff, data->bios_machineid, sizeof(buff));
 		break;

 	case I8K_FN_STATUS: