Thread (8 messages) 8 messages, 5 authors, 2026-03-10

Re: [PATCH] gpio: msc313: remove kcalloc

From: Linus Walleij <linusw@kernel.org>
Date: 2026-03-09 00:06:16
Also in: linux-gpio, linux-hardening, lkml

On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev [off-list ref] wrote:
Use a flexible array member to combine kzalloc and kcalloc.

Signed-off-by: Rosen Penev <redacted>
(...)
 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);
quoted hunk ↗ jump to hunk
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help