Skip to contentSkip to conversation

ACPI: ac: Use strscpy() instead of strcpy().

PATCH Applied Muhammad Qasim Abdul Majeed 2 participants 8 messages Aug 4, 2024 – Aug 26, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/6 ACPI: ac: Use strscpy() instead of strcpy().

Replace strcpy() with strscpy() in the ACPI ac driver. strcpy() has been deprecated because it is generally unsafe, so help to eliminate it from the kernel source.

---
 drivers/acpi/ac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/ac.c +2 -2
index 09a87fa222c7..ad1427a384e4 100644
@@ -213,8 +213,8 @@ 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);
+	strscpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
+	strscpy(acpi_device_class(adev), ACPI_AC_CLASS);
 
 	platform_set_drvdata(pdev, ac);
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/6 ACPI: acpi_pad: Use strscpy instead of strcpy.

Replace strcpy() with strscpy() in the ACPI acpi_pad driver. strcpy() has been deprecated because it is generally unsafe, so help to eliminate it from the kernel source.

---
 drivers/acpi/acpi_pad.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/acpi_pad.c +2 -2
index bd1ad07f0290..e49f89bbeacf 100644
@@ -417,8 +417,8 @@ static int acpi_pad_probe(struct platform_device *pdev)
 	struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
 	acpi_status status;
 
-	strcpy(acpi_device_name(adev), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
-	strcpy(acpi_device_class(adev), ACPI_PROCESSOR_AGGREGATOR_CLASS);
+	strscpy(acpi_device_name(adev), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
+	strscpy(acpi_device_class(adev), ACPI_PROCESSOR_AGGREGATOR_CLASS);
 
 	status = acpi_install_notify_handler(adev->handle,
 		ACPI_DEVICE_NOTIFY, acpi_pad_notify, adev);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 3/6 ACPI: acpi_processor: Use strscpy instead of strcpy.

In reply to Muhammad Qasim Abdul Majeed

Replace strcpy() with strscpy() in the ACPI acpi_processor driver. strcpy() has been deprecated because it is generally unsafe, so help to eliminate it from the kernel source.

---
 drivers/acpi/acpi_processor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/acpi_processor.c +2 -2
index 7a0dd35d62c9..8a8826a2242d 100644
@@ -394,8 +394,8 @@ static int acpi_processor_add(struct acpi_device *device,
 	}
 
 	pr->handle = device->handle;
-	strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
-	strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
+	strscpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
+	strscpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
 	device->driver_data = pr;
 
 	result = acpi_processor_get_info(device);
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 4/6 ACPI: battery : Use strscpy instead of strcpy.

In reply to Muhammad Qasim Abdul Majeed

Replace strcpy() with strscpy() in the ACPI battery driver. strcpy() has been deprecated because it is generally unsafe, so help to eliminate it from the kernel source.

---
 drivers/acpi/battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/battery.c +2 -2
index b379401ff1c2..784f9234f1a4 100644
@@ -1193,8 +1193,8 @@ static int acpi_battery_add(struct acpi_device *device)
 	if (!battery)
 		return -ENOMEM;
 	battery->device = device;
-	strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
-	strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
+	strscpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
+	strscpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
 	device->driver_data = battery;
 	mutex_init(&battery->lock);
 	mutex_init(&battery->sysfs_lock);
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 5/6 ACPI: button: Use strscpy instead of strcpy.

In reply to Muhammad Qasim Abdul Majeed

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.

---
 drivers/acpi/button.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/acpi/button.c +6 -7
index cc61020756be..9dda4a3998f8 100644
@@ -521,7 +521,7 @@ static int acpi_button_add(struct acpi_device *device)
 	struct input_dev *input;
 	const char *hid = acpi_device_hid(device);
 	acpi_status status;
-	char *name, *class;
+	char *class;
 	int error = 0;
 
 	if (!strcmp(hid, ACPI_BUTTON_HID_LID) &&
@@ -540,27 +540,26 @@ static int acpi_button_add(struct acpi_device *device)
 		goto err_free_button;
 	}
 
-	name = acpi_device_name(device);
 	class = acpi_device_class(device);
 
 	if (!strcmp(hid, ACPI_BUTTON_HID_POWER) ||
 	    !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
 		button->type = ACPI_BUTTON_TYPE_POWER;
 		handler = acpi_button_notify;
-		strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
+		strscpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_POWER);
 		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(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_SLEEP);
 		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(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_LID);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
 		input->open = acpi_lid_input_open;
@@ -579,7 +578,7 @@ static int acpi_button_add(struct acpi_device *device)
 
 	snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
 
-	input->name = name;
+	input->name = acpi_device_name(device);
 	input->phys = button->phys;
 	input->id.bustype = BUS_HOST;
 	input->id.product = button->type;
@@ -636,7 +635,7 @@ static int acpi_button_add(struct acpi_device *device)
 	}
 
 	device_init_wakeup(&device->dev, true);
-	pr_info("%s [%s]\n", name, acpi_device_bid(device));
+	pr_info("%s [%s]\n", input->name, acpi_device_bid(device));
 	return 0;
 
 err_input_unregister:
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v2 5/6] ACPI: button: Use strscpy instead of strcpy.

Quoted 27 lines · Muhammad Qasim Abdul Majeed

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.

---
 drivers/acpi/button.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/acpi/button.c +1 -1
index cc61020756be..9dda4a3998f8 100644
@@ -521,7 +521,7 @@ static int acpi_button_add(struct acpi_device *device)
        struct input_dev *input;
        const char *hid = acpi_device_hid(device);
        acpi_status status;
-       char *name, *class;
+       char *class;
        int error = 0;
 
        if (!strcmp(hid, ACPI_BUTTON_HID_LID) &&

drivers/acpi/button.c static int acpi_button_add(struct acpi_device *device) · line 543

Quoted 4 lines
drivers/acpi/button.c +0 -1
@@ -540,27 +540,26 @@ static int acpi_button_add(struct acpi_device *device)
                goto err_free_button;
        }
 
-       name = acpi_device_name(device);

This is more than advertised in the changelog.

Please extend the changelog to explain why this additional change is needed.

Quoted 47 lines
drivers/acpi/button.c +5 -6
        class = acpi_device_class(device);
 
        if (!strcmp(hid, ACPI_BUTTON_HID_POWER) ||
            !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
                button->type = ACPI_BUTTON_TYPE_POWER;
                handler = acpi_button_notify;
-               strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
+               strscpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_POWER);
                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(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_SLEEP);
                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(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_LID);
                sprintf(class, "%s/%s",
                        ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
                input->open = acpi_lid_input_open;
@@ -579,7 +578,7 @@ static int acpi_button_add(struct acpi_device *device)
 
        snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
 
-       input->name = name;
+       input->name = acpi_device_name(device);
        input->phys = button->phys;
        input->id.bustype = BUS_HOST;
        input->id.product = button->type;
@@ -636,7 +635,7 @@ static int acpi_button_add(struct acpi_device *device)
        }
 
        device_init_wakeup(&device->dev, true);
-       pr_info("%s [%s]\n", name, acpi_device_bid(device));
+       pr_info("%s [%s]\n", input->name, acpi_device_bid(device));
        return 0;
 
 err_input_unregister:
--

2.34.1

#6 lore raw

PATCH v2 6/6 ACPI: bus: Define and use a macro for device and class name length.

In reply to Muhammad Qasim Abdul Majeed
---
 include/acpi/acpi_bus.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
include/acpi/acpi_bus.h +4 -3
index 1a4dfd7a1c4a..74ed1170fe66 100644
@@ -226,11 +226,12 @@ struct acpi_device_dir {
 #define acpi_device_dir(d)	((d)->dir.entry)
 
 /* Plug and Play */
-
+#define MAX_ACPI_DEVICE_NAME_LEN	40
+#define MAX_ACPI_CLASS_NAME_LEN		20
 typedef char acpi_bus_id[8];
 typedef u64 acpi_bus_address;
-typedef char acpi_device_name[40];
-typedef char acpi_device_class[20];
+typedef char acpi_device_name[MAX_ACPI_DEVICE_NAME_LEN];
+typedef char acpi_device_class[MAX_ACPI_CLASS_NAME_LEN];
 
 struct acpi_hardware_id {
 	struct list_head list;
Signature · 1 line
2.34.1
maintainer Applied
#7 lore raw
In reply to Muhammad Qasim Abdul Majeed
Quoted 18 lines · Muhammad Qasim Abdul Majeed

Replace strcpy() with strscpy() in the ACPI ac driver. strcpy() has been deprecated because it is generally unsafe, so help to eliminate it from the kernel source.

---
 drivers/acpi/ac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/ac.c +0 -0
index 09a87fa222c7..ad1427a384e4 100644
@@ -213,8 +213,8 @@ static int acpi_ac_probe(struct platform_device *pdev)
                return -ENOMEM;

drivers/acpi/ac.c static int acpi_ac_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/acpi/ac.c +2 -3
 
        ac->device = adev;
-       strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
-       strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
+       strscpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
+       strscpy(acpi_device_class(adev), ACPI_AC_CLASS);
 
        platform_set_drvdata(pdev, ac);
 
--

Applied as 6.12 material with some subject and changelog edits along with patches [2-4/6] and [6/6].

Patch [6/6] needs more work (I'll send a reply to it directly).

Thanks!