From: Rosen Penev Date: Tue, 30 Dec 2025 03:53:50 +0000 (-0800) Subject: button-hotplug: use flex array and not pointer hack X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4e285049e9c3f2e21e338cd9f7b0ee40a9b6811;p=thirdparty%2Fopenwrt.git button-hotplug: use flex array and not pointer hack 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 Link: https://github.com/openwrt/openwrt/pull/22170 Signed-off-by: Robert Marko --- diff --git a/package/kernel/button-hotplug/src/button-hotplug.c b/package/kernel/button-hotplug/src/button-hotplug.c index 2819d29b941..cec3c50a944 100644 --- a/package/kernel/button-hotplug/src/button-hotplug.c +++ b/package/kernel/button-hotplug/src/button-hotplug.c @@ -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;