]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
gpio-button-hotplug: avoid a const cast 22619/head
authorRosen Penev <rosenp@gmail.com>
Sat, 21 Mar 2026 21:44:36 +0000 (14:44 -0700)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Mon, 1 Jun 2026 07:34:39 +0000 (09:34 +0200)
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>
package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c

index 7c4c23bfc2b3c18da68f26e4bbdcaa2e3e320874..b97deba7634ea7ef7c138d7d2c21fcb362e208d0 100644 (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)
-               return ERR_PTR(-ENOMEM);
-
-       pdata->buttons = devm_kmalloc_array(dev, nbuttons, sizeof(struct gpio_keys_button), GFP_KERNEL);
-       if (!pdata->buttons)
+       buttons = devm_kmalloc_array(dev, nbuttons, sizeof(struct gpio_keys_button), GFP_KERNEL);
+       if (!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;
 }