Browse Source

gpio-button-hotplug: use devm_kmemdup_array

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]>
Rosen Penev 1 month ago
parent
commit
616b0cebe7
1 changed files with 1 additions and 2 deletions
  1. 1 2
      package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c

+ 1 - 2
package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c

@@ -463,13 +463,12 @@ static int gpio_keys_button_probe(struct platform_device *pdev,
 		return -EINVAL;
 		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);
 		       GFP_KERNEL);
 	if (!buttons) {
 	if (!buttons) {
 		dev_err(dev, "no memory for button data\n");
 		dev_err(dev, "no memory for button data\n");
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
-	memcpy(buttons, pdata->buttons, pdata->nbuttons * sizeof(struct gpio_keys_button));
 
 
 	bdev = devm_kzalloc(dev, sizeof(struct gpio_keys_button_dev) +
 	bdev = devm_kzalloc(dev, sizeof(struct gpio_keys_button_dev) +
 		       pdata->nbuttons * sizeof(struct gpio_keys_button_data),
 		       pdata->nbuttons * sizeof(struct gpio_keys_button_data),