1
1

gpio-button-hotplug: avoid a const cast

Introduce a variable inside probe to avoid having to cast const away.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/22619
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
This commit is contained in:
Rosen Penev 2026-03-21 14:44:36 -07:00 committed by Jonas Jelonek
parent 80a44d6a52
commit 805098d8b6
No known key found for this signature in database

View File

@ -365,6 +365,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
{
struct device_node *node = dev->of_node;
struct gpio_keys_platform_data *pdata;
struct gpio_keys_button *buttons;
int nbuttons;
int i = 0;
@ -372,21 +373,12 @@ gpio_keys_get_devtree_pdata(struct device *dev)
if (nbuttons == 0)
return ERR_PTR(-EINVAL);
pdata = devm_kzalloc(dev, sizeof(struct gpio_keys_platform_data), GFP_KERNEL);
if (!pdata)
buttons = devm_kmalloc_array(dev, nbuttons, sizeof(struct gpio_keys_button), GFP_KERNEL);
if (!buttons)
return ERR_PTR(-ENOMEM);
pdata->buttons = devm_kmalloc_array(dev, nbuttons, sizeof(struct gpio_keys_button), GFP_KERNEL);
if (!pdata->buttons)
return ERR_PTR(-ENOMEM);
pdata->nbuttons = nbuttons;
pdata->rep = of_property_present(node, "autorepeat");
of_property_read_u32(node, "poll-interval", &pdata->poll_interval);
for_each_available_child_of_node_scoped(node, pp) {
struct gpio_keys_button *button = (struct gpio_keys_button *)&pdata->buttons[i++];
struct gpio_keys_button *button = &buttons[i++];
if (of_property_read_u32(pp, "linux,code", &button->code)) {
dev_err(dev, "Button node '%s' without keycode\n",
@ -409,6 +401,15 @@ gpio_keys_get_devtree_pdata(struct device *dev)
button->gpio = -ENOENT; /* mark this as device-tree */
}
pdata = devm_kzalloc(dev, sizeof(struct gpio_keys_platform_data), GFP_KERNEL);
if (!pdata)
return ERR_PTR(-ENOMEM);
pdata->nbuttons = nbuttons;
pdata->buttons = buttons;
pdata->rep = of_property_present(node, "autorepeat");
of_property_read_u32(node, "poll-interval", &pdata->poll_interval);
return pdata;
}