diff mbox series

ACPI: thermal: Use strscpy() instead of strcpy()

Message ID 20240912205922.302036-1-abdul.rahim@myyahoo.com (mailing list archive)
State Superseded, archived
Headers show
Series ACPI: thermal: Use strscpy() instead of strcpy() | expand

Commit Message

Abdul Rahim Sept. 12, 2024, 8:59 p.m. UTC
thermal: prefer strscpy() over strcpy()

strcpy() is generally considered unsafe and use of strscpy() is
recommended [1]

this fixes checkpatch warning:
	WARNING: Prefer strscpy over strcpy

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Abdul Rahim <abdul.rahim@myyahoo.com>
---
 drivers/acpi/thermal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Christophe JAILLET Sept. 13, 2024, 3:17 p.m. UTC | #1
Le 12/09/2024 à 22:59, Abdul Rahim a écrit :
> thermal: prefer strscpy() over strcpy()
> 
> strcpy() is generally considered unsafe and use of strscpy() is
> recommended [1]
> 
> this fixes checkpatch warning:
> 	WARNING: Prefer strscpy over strcpy
> 
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
> Signed-off-by: Abdul Rahim <abdul.rahim@myyahoo.com>
> ---
>   drivers/acpi/thermal.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> index 78db38c7076e..a35e40976763 100644
> --- a/drivers/acpi/thermal.c
> +++ b/drivers/acpi/thermal.c
> @@ -796,9 +796,9 @@ static int acpi_thermal_add(struct acpi_device *device)
>   		return -ENOMEM;
>   
>   	tz->device = device;
> -	strcpy(tz->name, device->pnp.bus_id);
> -	strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
> -	strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
> +	strscpy(tz->name, device->pnp.bus_id);
> +	strscpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);

Why the 3 parameters version here only?
Is it needed?

CJ

> +	strscpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
>   	device->driver_data = tz;
>   
>   	acpi_thermal_aml_dependency_fix(tz);
Abdul Rahim Sept. 13, 2024, 6:13 p.m. UTC | #2
On Fri, Sep 13, 2024 at 05:17:58PM GMT, Christophe JAILLET wrote:
> Le 12/09/2024 � 22:59, Abdul Rahim a �crit�:
> > thermal: prefer strscpy() over strcpy()
> > 
> > strcpy() is generally considered unsafe and use of strscpy() is
> > recommended [1]
> > 
> > this fixes checkpatch warning:
> > 	WARNING: Prefer strscpy over strcpy
> > 
> > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
> > Signed-off-by: Abdul Rahim <abdul.rahim@myyahoo.com>
> > ---
> >   drivers/acpi/thermal.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> > index 78db38c7076e..a35e40976763 100644
> > --- a/drivers/acpi/thermal.c
> > +++ b/drivers/acpi/thermal.c
> > @@ -796,9 +796,9 @@ static int acpi_thermal_add(struct acpi_device *device)
> >   		return -ENOMEM;
> >   	tz->device = device;
> > -	strcpy(tz->name, device->pnp.bus_id);
> > -	strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
> > -	strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
> > +	strscpy(tz->name, device->pnp.bus_id);
> > +	strscpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
> 
> Why the 3 parameters version here only?
> Is it needed?
> 
> CJ
> 
> > +	strscpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
> >   	device->driver_data = tz;
> >   	acpi_thermal_aml_dependency_fix(tz);

You are correct, it's actually not needed.

"The size argument ... is only required when dst is not an array" [1]

And destination buffers here are actually arrays
from `include/acpi/acpi_bus.h`

```
typedef char acpi_bus_id[8];
...
typedef char acpi_device_name[40];
typedef char acpi_device_class[20];
```
https://docs.kernel.org/core-api/kernel-api.html#c.strscpy [1]

I will resend this patch, with the parameter removed.

Thanks,
Abdul Rahim
diff mbox series

Patch

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 78db38c7076e..a35e40976763 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -796,9 +796,9 @@  static int acpi_thermal_add(struct acpi_device *device)
 		return -ENOMEM;
 
 	tz->device = device;
-	strcpy(tz->name, device->pnp.bus_id);
-	strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
-	strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
+	strscpy(tz->name, device->pnp.bus_id);
+	strscpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
+	strscpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
 	device->driver_data = tz;
 
 	acpi_thermal_aml_dependency_fix(tz);