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 <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/22170
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
Rosen Penev 2025-12-29 19:53:50 -08:00 committed by Robert Marko
parent 7a76074574
commit c4e285049e

View 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;