]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/x86: Use strscpy()/scnprintf() with acpi_device_name/class()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 7 Apr 2025 17:08:38 +0000 (20:08 +0300)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 11 Apr 2025 11:04:13 +0000 (14:04 +0300)
Replace strcpy() and sprintf() for acpi_device_name/class() targets
with safer variant. In one case, scnprintf() is necessary but the
rest can use strscpy().

Link: https://lore.kernel.org/r/20250407170839.2153-1-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/eeepc-laptop.c
drivers/platform/x86/panasonic-laptop.c
drivers/platform/x86/sony-laptop.c
drivers/platform/x86/thinkpad_acpi.c
drivers/platform/x86/topstar-laptop.c
drivers/platform/x86/xo15-ebook.c

index f52fbc4924d4eecf6d17c48f35a66025408e3871..d1908815f5a271b80651261a57a2ca96fb017583 100644 (file)
@@ -1370,8 +1370,8 @@ static int eeepc_acpi_add(struct acpi_device *device)
        if (!eeepc)
                return -ENOMEM;
        eeepc->handle = device->handle;
-       strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
-       strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
+       strscpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
+       strscpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
        device->driver_data = eeepc;
        eeepc->device = device;
 
index 2987b4db60096bbb85c14ce208c37680a08110d2..255317e6fec88153ca89c307da8bec3e817d78cb 100644 (file)
@@ -1033,8 +1033,8 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
        pcc->handle = device->handle;
        pcc->num_sifr = num_sifr;
        device->driver_data = pcc;
-       strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
-       strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
+       strscpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
+       strscpy(acpi_device_class(device), ACPI_PCC_CLASS);
 
        result = acpi_pcc_init_input(pcc);
        if (result) {
index 9144a51920f1fa794f17cbc882609b3a4db6b796..492c275ba9acd46d23ac7aabe5bd986f2cd96dd1 100644 (file)
@@ -3157,7 +3157,7 @@ static int sony_nc_add(struct acpi_device *device)
        struct sony_nc_value *item;
 
        sony_nc_acpi_device = device;
-       strcpy(acpi_device_class(device), "sony/hotkey");
+       strscpy(acpi_device_class(device), "sony/hotkey");
 
        sony_nc_acpi_handle = device->handle;
 
@@ -4679,7 +4679,7 @@ static int sony_pic_add(struct acpi_device *device)
        struct sony_pic_irq *irq, *tmp_irq;
 
        spic_dev.acpi_dev = device;
-       strcpy(acpi_device_class(device), "sony/hotkey");
+       strscpy(acpi_device_class(device), "sony/hotkey");
        sony_pic_detect_device_type(&spic_dev);
        mutex_init(&spic_dev.lock);
 
index 5790095c175e6fe94fc0edaf38346723485459ea..9bb191a32e8073a0a9d2ec6c5b0b2b0802b7249d 100644 (file)
@@ -836,9 +836,9 @@ static int __init setup_acpi_notify(struct ibm_struct *ibm)
        }
 
        ibm->acpi->device->driver_data = ibm;
-       sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
-               TPACPI_ACPI_EVENT_PREFIX,
-               ibm->name);
+       scnprintf(acpi_device_class(ibm->acpi->device),
+                 sizeof(acpi_device_class(ibm->acpi->device)),
+                 "%s/%s", TPACPI_ACPI_EVENT_PREFIX, ibm->name);
 
        status = acpi_install_notify_handler(*ibm->acpi->handle,
                        ibm->acpi->type, dispatch_acpi_notify, ibm);
index 20df1ebefc30e4c27abe53a00d9bb5cefe1bcd99..53fc2b3645529eb352a10c8b3924e21f2d65229d 100644 (file)
@@ -296,8 +296,8 @@ static int topstar_acpi_add(struct acpi_device *device)
        if (!topstar)
                return -ENOMEM;
 
-       strcpy(acpi_device_name(device), "Topstar TPSACPI");
-       strcpy(acpi_device_class(device), TOPSTAR_LAPTOP_CLASS);
+       strscpy(acpi_device_name(device), "Topstar TPSACPI");
+       strscpy(acpi_device_class(device), TOPSTAR_LAPTOP_CLASS);
        device->driver_data = topstar;
        topstar->device = device;
 
index df2bf1c585239b27f22fb2936733fb0223ba323e..cb02222c978c09e06acd130dcfcc7456879d9832 100644 (file)
@@ -84,7 +84,6 @@ static int ebook_switch_add(struct acpi_device *device)
        const struct acpi_device_id *id;
        struct ebook_switch *button;
        struct input_dev *input;
-       char *name, *class;
        int error;
 
        button = kzalloc(sizeof(struct ebook_switch), GFP_KERNEL);
@@ -99,9 +98,6 @@ static int ebook_switch_add(struct acpi_device *device)
                goto err_free_button;
        }
 
-       name = acpi_device_name(device);
-       class = acpi_device_class(device);
-
        id = acpi_match_acpi_device(ebook_device_ids, device);
        if (!id) {
                dev_err(&device->dev, "Unsupported hid\n");
@@ -109,12 +105,12 @@ static int ebook_switch_add(struct acpi_device *device)
                goto err_free_input;
        }
 
-       strcpy(name, XO15_EBOOK_DEVICE_NAME);
-       sprintf(class, "%s/%s", XO15_EBOOK_CLASS, XO15_EBOOK_SUBCLASS);
+       strscpy(acpi_device_name(device), XO15_EBOOK_DEVICE_NAME);
+       strscpy(acpi_device_class(device), XO15_EBOOK_CLASS "/" XO15_EBOOK_SUBCLASS);
 
        snprintf(button->phys, sizeof(button->phys), "%s/button/input0", id->id);
 
-       input->name = name;
+       input->name = acpi_device_name(device);
        input->phys = button->phys;
        input->id.bustype = BUS_HOST;
        input->dev.parent = &device->dev;