* [PATCHv2] gpio: msc313: remove kcalloc
@ 2026-03-20 1:53 Rosen Penev
2026-03-20 13:39 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-20 1:53 UTC (permalink / raw)
To: linux-gpio
Cc: Daniel Palmer, Romain Perier, Linus Walleij, Bartosz Golaszewski,
Kees Cook, Gustavo A. R. Silva,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Use a flexible array member to combine kzalloc and kcalloc.
Add an extra counting member to support __counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: add __counted_by.
drivers/gpio/gpio-msc313.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-msc313.c b/drivers/gpio/gpio-msc313.c
index 7345afdc78de..2accf3446cd9 100644
--- a/drivers/gpio/gpio-msc313.c
+++ b/drivers/gpio/gpio-msc313.c
@@ -483,7 +483,8 @@ MSC313_GPIO_CHIPDATA(ssd20xd);
struct msc313_gpio {
void __iomem *base;
const struct msc313_gpio_data *gpio_data;
- u8 *saved;
+ int nr_saved;
+ u8 saved[] __counted_by(nr_saved);
};
static int msc313_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
@@ -631,16 +632,13 @@ 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->nr_saved = match_data->num;
gpio->gpio_data = match_data;
- gpio->saved = devm_kcalloc(dev, gpio->gpio_data->num, sizeof(*gpio->saved), GFP_KERNEL);
- if (!gpio->saved)
- return -ENOMEM;
-
gpio->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(gpio->base))
return PTR_ERR(gpio->base);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCHv2] gpio: msc313: remove kcalloc
2026-03-20 1:53 [PATCHv2] gpio: msc313: remove kcalloc Rosen Penev
@ 2026-03-20 13:39 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2026-03-20 13:39 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-gpio, Daniel Palmer, Romain Perier, Bartosz Golaszewski,
Kees Cook, Gustavo A. R. Silva,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Fri, Mar 20, 2026 at 2:53 AM Rosen Penev <rosenp@gmail.com> wrote:
> Use a flexible array member to combine kzalloc and kcalloc.
>
> Add an extra counting member to support __counted_by.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-20 13:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 1:53 [PATCHv2] gpio: msc313: remove kcalloc Rosen Penev
2026-03-20 13:39 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox