On Sun, Mar 8, 2026 at 5:06 PM Linus Walleij <[email protected]> wrote: > > On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev <[email protected]> wrote: > > > Use a flexible array member to combine kzalloc and kcalloc. > > > > Signed-off-by: Rosen Penev <[email protected]> > (...) > > struct msc313_gpio { > > void __iomem *base; > > const struct msc313_gpio_data *gpio_data; > > Do you wanna add: > > const unsigned int saved_size; So in the code there's
for (i = 0; i < gpio->gpio_data->num; i++) which is equivalent to match->num. __counted_by doesn't support pointers AFAIK. > > > - u8 *saved; > > + u8 saved[]; > > u8 saved[] __counted_by(saved_size); > > > static int msc313_gpio_set(struct gpio_chip *chip, unsigned int offset, > > int value) > > @@ -631,16 +631,12 @@ static int msc313_gpio_probe(struct platform_device > > *pdev) > > if (!parent_domain) > > return -ENODEV; > > > > - gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); > > + gpio = devm_kzalloc(dev, struct_size(gpio, saved, match_data->num), > > GFP_KERNEL); > > if (!gpio) > > return -ENOMEM; > > gpio->saved_size = match_data->num; > > I know it takes some bytes more but it feels way safer. > > Yours, > Linus Walleij

