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

