gpio-button-hotplug: use devm_kmemdup_array

Eliminates a manual memcpy.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/19932
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
Rosen Penev 2025-11-28 15:31:24 -08:00 committed by Hauke Mehrtens
parent 5b263f3360
commit 616b0cebe7

View 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),