diff mbox series

ACPI: button: Use strscpy instead of strcpy.

Message ID 20240901191826.421488-1-qasim.majeed20@gmail.com
State Accepted
Commit 7fcf82e7348766840e5e259488662751c6db22a7
Headers show
Series ACPI: button: Use strscpy instead of strcpy. | expand

Commit Message

Muhammad Qasim Abdul Majeed Sept. 1, 2024, 7:18 p.m. UTC
Replace strcpy() with strscpy() in the ACPI button driver.

strcpy() has been deprecated because it is generally unsafe, so help to
eliminate it from the kernel source.

Link: https://github.com/KSPP/linux/issues/88

Signed-off-by: Muhammad Qasim Abdul Majeed <qasim.majeed20@gmail.com>
<This is more than advertised in the changelog>
The patch has been updated.
---
 drivers/acpi/button.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Rafael J. Wysocki Sept. 3, 2024, 2:30 p.m. UTC | #1
On Sun, Sep 1, 2024 at 9:18 PM Muhammad Qasim Abdul Majeed
<qasim.majeed20@gmail.com> wrote:
>
> Replace strcpy() with strscpy() in the ACPI button driver.
>
> strcpy() has been deprecated because it is generally unsafe, so help to
> eliminate it from the kernel source.
>
> Link: https://github.com/KSPP/linux/issues/88
>
> Signed-off-by: Muhammad Qasim Abdul Majeed <qasim.majeed20@gmail.com>
> <This is more than advertised in the changelog>
> The patch has been updated.
> ---
>  drivers/acpi/button.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
> index cc61020756be..51470208e6da 100644
> --- a/drivers/acpi/button.c
> +++ b/drivers/acpi/button.c
> @@ -547,20 +547,20 @@ static int acpi_button_add(struct acpi_device *device)
>             !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
>                 button->type = ACPI_BUTTON_TYPE_POWER;
>                 handler = acpi_button_notify;
> -               strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
> +               strscpy(name, ACPI_BUTTON_DEVICE_NAME_POWER, MAX_ACPI_DEVICE_NAME_LEN);
>                 sprintf(class, "%s/%s",
>                         ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
>         } else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) ||
>                    !strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) {
>                 button->type = ACPI_BUTTON_TYPE_SLEEP;
>                 handler = acpi_button_notify;
> -               strcpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP);
> +               strscpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP, MAX_ACPI_DEVICE_NAME_LEN);
>                 sprintf(class, "%s/%s",
>                         ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
>         } else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) {
>                 button->type = ACPI_BUTTON_TYPE_LID;
>                 handler = acpi_lid_notify;
> -               strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
> +               strscpy(name, ACPI_BUTTON_DEVICE_NAME_LID, MAX_ACPI_DEVICE_NAME_LEN);
>                 sprintf(class, "%s/%s",
>                         ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
>                 input->open = acpi_lid_input_open;
> --

Applied as 6.12 material, thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index cc61020756be..51470208e6da 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -547,20 +547,20 @@  static int acpi_button_add(struct acpi_device *device)
 	    !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
 		button->type = ACPI_BUTTON_TYPE_POWER;
 		handler = acpi_button_notify;
-		strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
+		strscpy(name, ACPI_BUTTON_DEVICE_NAME_POWER, MAX_ACPI_DEVICE_NAME_LEN);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
 	} else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) ||
 		   !strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) {
 		button->type = ACPI_BUTTON_TYPE_SLEEP;
 		handler = acpi_button_notify;
-		strcpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP);
+		strscpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP, MAX_ACPI_DEVICE_NAME_LEN);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
 	} else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) {
 		button->type = ACPI_BUTTON_TYPE_LID;
 		handler = acpi_lid_notify;
-		strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
+		strscpy(name, ACPI_BUTTON_DEVICE_NAME_LID, MAX_ACPI_DEVICE_NAME_LEN);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
 		input->open = acpi_lid_input_open;