mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +00:00
002cdb95dc
One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example: struct gpio_keys_drvdata { ... struct gpio_button_data data[0]; }; size = sizeof(struct gpio_keys_drvdata) + count * sizeof(struct gpio_button_data); instance = devm_kzalloc(dev, size, GFP_KERNEL); Instead of leaving these open-coded and prone to type mistakes, we can now use the new struct_size() helper: instance = devm_kzalloc(dev, struct_size(instance, data, count), GFP_KERNEL); Notice that, in this case, variable size is not necessary, hence it is removed. This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> |
||
---|---|---|
.. | ||
adc-keys.c | ||
adp5520-keys.c | ||
adp5588-keys.c | ||
adp5589-keys.c | ||
amikbd.c | ||
atakbd.c | ||
atkbd.c | ||
bcm-keypad.c | ||
cap11xx.c | ||
clps711x-keypad.c | ||
cros_ec_keyb.c | ||
davinci_keyscan.c | ||
dlink-dir685-touchkeys.c | ||
ep93xx_keypad.c | ||
goldfish_events.c | ||
gpio_keys_polled.c | ||
gpio_keys.c | ||
hil_kbd.c | ||
hilkbd.c | ||
hpps2atkbd.h | ||
imx_keypad.c | ||
ipaq-micro-keys.c | ||
jornada680_kbd.c | ||
jornada720_kbd.c | ||
Kconfig | ||
lkkbd.c | ||
lm8323.c | ||
lm8333.c | ||
locomokbd.c | ||
lpc32xx-keys.c | ||
Makefile | ||
maple_keyb.c | ||
matrix_keypad.c | ||
max7359_keypad.c | ||
mcs_touchkey.c | ||
mpr121_touchkey.c | ||
mtk-pmic-keys.c | ||
newtonkbd.c | ||
nomadik-ske-keypad.c | ||
nspire-keypad.c | ||
omap4-keypad.c | ||
omap-keypad.c | ||
opencores-kbd.c | ||
pmic8xxx-keypad.c | ||
pxa27x_keypad.c | ||
pxa930_rotary.c | ||
qt1050.c | ||
qt1070.c | ||
qt2160.c | ||
samsung-keypad.c | ||
sh_keysc.c | ||
snvs_pwrkey.c | ||
spear-keyboard.c | ||
st-keyscan.c | ||
stmpe-keypad.c | ||
stowaway.c | ||
sun4i-lradc-keys.c | ||
sunkbd.c | ||
tc3589x-keypad.c | ||
tca6416-keypad.c | ||
tca8418_keypad.c | ||
tegra-kbc.c | ||
tm2-touchkey.c | ||
twl4030_keypad.c | ||
w90p910_keypad.c | ||
xtkbd.c |