Skip to content

Commit c4e2850

Browse files
nehebrobimarko
authored andcommitted
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: openwrt/openwrt#22170 Signed-off-by: Robert Marko <robimarko@gmail.com>
1 parent 7a76074 commit c4e2850

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

package/kernel/button-hotplug/src/button-hotplug.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
#endif
4747

4848
struct bh_priv {
49-
unsigned long *seen;
5049
struct input_handle handle;
50+
unsigned long seen[];
5151
};
5252

5353
struct bh_event {
@@ -254,13 +254,10 @@ static int button_hotplug_connect(struct input_handler *handler,
254254
if (i == ARRAY_SIZE(button_map))
255255
return -ENODEV;
256256

257-
priv = kzalloc(sizeof(*priv) +
258-
(sizeof(unsigned long) * ARRAY_SIZE(button_map)),
259-
GFP_KERNEL);
257+
priv = kzalloc(struct_size(priv, seen, ARRAY_SIZE(button_map)), GFP_KERNEL);
260258
if (!priv)
261259
return -ENOMEM;
262260

263-
priv->seen = (unsigned long *) &priv[1];
264261
priv->handle.private = priv;
265262
priv->handle.dev = dev;
266263
priv->handle.handler = handler;

0 commit comments

Comments
 (0)