Re: [PATCH] gpio: msc313: remove kcalloc
From: Rosen Penev <hidden>
Date: 2026-03-09 01:27:34
Also in:
linux-gpio, linux-hardening, lkml
From: Rosen Penev <hidden>
Date: 2026-03-09 01:27:34
Also in:
linux-gpio, linux-hardening, lkml
On Sun, Mar 8, 2026 at 5:06 PM Linus Walleij [off-list ref] wrote:
On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev [off-list ref] wrote:quoted
Use a flexible array member to combine kzalloc and kcalloc. Signed-off-by: Rosen Penev <redacted>(...)quoted
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.
quoted
- u8 *saved; + u8 saved[];u8 saved[] __counted_by(saved_size);quoted
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