]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
button-hotplug: use flex array and not pointer hack 22170/head
authorRosen Penev <rosenp@gmail.com>
Tue, 30 Dec 2025 03:53:50 +0000 (19:53 -0800)
committerRobert Marko <robimarko@gmail.com>
Tue, 3 Mar 2026 12:09:35 +0000 (13:09 +0100)
The &pointer + 1 trick is a C89 trick to point to area allocated after
the size of the struct. We have struct_size and flex arrays now.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/22170
Signed-off-by: Robert Marko <robimarko@gmail.com>
package/kernel/button-hotplug/src/button-hotplug.c

index 2819d29b94182531de0fa4d506c74a4df2251a6e..cec3c50a9442bc252c8af47289d8bd7baf76e3ee 100644 (file)
@@ -46,8 +46,8 @@
 #endif
 
 struct bh_priv {
-       unsigned long           *seen;
        struct input_handle     handle;
+       unsigned long           seen[];
 };
 
 struct bh_event {
@@ -254,13 +254,10 @@ static int button_hotplug_connect(struct input_handler *handler,
        if (i == ARRAY_SIZE(button_map))
                return -ENODEV;
 
-       priv = kzalloc(sizeof(*priv) +
-                      (sizeof(unsigned long) * ARRAY_SIZE(button_map)),
-                      GFP_KERNEL);
+       priv = kzalloc(struct_size(priv, seen, ARRAY_SIZE(button_map)), GFP_KERNEL);
        if (!priv)
                return -ENOMEM;
 
-       priv->seen = (unsigned long *) &priv[1];
        priv->handle.private = priv;
        priv->handle.dev = dev;
        priv->handle.handler = handler;