gpio-button-hotplug: use devm_kmemdup_array
authorRosen Penev <[email protected]>
Fri, 28 Nov 2025 23:31:24 +0000 (15:31 -0800)
committerHauke Mehrtens <[email protected]>
Tue, 2 Dec 2025 22:32:42 +0000 (23:32 +0100)
Eliminates a manual memcpy.

Signed-off-by: Rosen Penev <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/19932
Signed-off-by: Hauke Mehrtens <[email protected]>
package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c

index 5b40e34950cc356195525c980c8165ac3633cab1..d0e35bedee4f6a4b0091f91ac4a1aef186855c3d 100644 (file)
@@ -463,13 +463,12 @@ static int gpio_keys_button_probe(struct platform_device *pdev,
                return -EINVAL;
        }
 
-       buttons = devm_kzalloc(dev, pdata->nbuttons * sizeof(struct gpio_keys_button),
+       buttons = devm_kmemdup_array(dev, pdata->buttons, pdata->nbuttons, sizeof(struct gpio_keys_button),
                       GFP_KERNEL);
        if (!buttons) {
                dev_err(dev, "no memory for button data\n");
                return -ENOMEM;
        }
-       memcpy(buttons, pdata->buttons, pdata->nbuttons * sizeof(struct gpio_keys_button));
 
        bdev = devm_kzalloc(dev, sizeof(struct gpio_keys_button_dev) +
                       pdata->nbuttons * sizeof(struct gpio_keys_button_data),