[PATCH] Staging: acpi: fixed a coding style issue moving from strcpy to strscpy.

Thomas Andreatta posted 1 patch 1 year, 7 months ago
drivers/acpi/ac.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
[PATCH] Staging: acpi: fixed a coding style issue moving from strcpy to strscpy.
Posted by Thomas Andreatta 1 year, 7 months ago
fixed a coding style issue moving from strcpy to strscpy.

Signed-off-by: Thomas Andreatta <thomas.andreatta2000@gmail.com>
---
 drivers/acpi/ac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 09a87fa222c7..f4b5ba033df8 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -213,8 +213,11 @@ static int acpi_ac_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	ac->device = adev;
-	strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
-	strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
+	char *device_class = acpi_device_class(adev);
+	char *device_name = acpi_device_name(adev);
+
+	strscpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME, strlen(device_name));
+	strscpy(device_class, ACPI_AC_CLASS, strlen(device_class));
 
 	platform_set_drvdata(pdev, ac);
 
-- 
2.34.1
Re: [PATCH] Staging: acpi: fixed a coding style issue moving from strcpy to strscpy.
Posted by Rafael J. Wysocki 1 year, 7 months ago
On Fri, Jul 5, 2024 at 9:18 PM Thomas Andreatta
<thomasandreatta2000@gmail.com> wrote:
>
> fixed a coding style issue moving from strcpy to strscpy.

This is not a coding style issue and the change below is not a fix.

It just replaces strcpy() with strscpy() which is preferred (for some
reason that needs to be mentioned).

> Signed-off-by: Thomas Andreatta <thomas.andreatta2000@gmail.com>
> ---
>  drivers/acpi/ac.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
> index 09a87fa222c7..f4b5ba033df8 100644
> --- a/drivers/acpi/ac.c
> +++ b/drivers/acpi/ac.c
> @@ -213,8 +213,11 @@ static int acpi_ac_probe(struct platform_device *pdev)
>                 return -ENOMEM;
>
>         ac->device = adev;
> -       strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
> -       strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
> +       char *device_class = acpi_device_class(adev);
> +       char *device_name = acpi_device_name(adev);
> +
> +       strscpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME, strlen(device_name));
> +       strscpy(device_class, ACPI_AC_CLASS, strlen(device_class));

The last argument of strscpy() is not necessary in both cases.

>
>         platform_set_drvdata(pdev, ac);
>
> --