* [PATCH] gpio: msc313: remove kcalloc
@ 2026-03-08 2:15 Rosen Penev
2026-03-08 5:59 ` Daniel Palmer
2026-03-09 0:06 ` Linus Walleij
0 siblings, 2 replies; 8+ messages in thread
From: Rosen Penev @ 2026-03-08 2:15 UTC (permalink / raw)
To: linux-gpio
Cc: Daniel Palmer, linux-hardening, gustavoars, Romain Perier,
Linus Walleij, Bartosz Golaszewski,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
Use a flexible array member to combine kzalloc and kcalloc.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-msc313.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-msc313.c b/drivers/gpio/gpio-msc313.c
index 7345afdc78de..de3e6da2a089 100644
--- a/drivers/gpio/gpio-msc313.c
+++ b/drivers/gpio/gpio-msc313.c
@@ -483,7 +483,7 @@ MSC313_GPIO_CHIPDATA(ssd20xd);
struct msc313_gpio {
void __iomem *base;
const struct msc313_gpio_data *gpio_data;
- u8 *saved;
+ u8 saved[];
};
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->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] 8+ messages in thread
* Re: [PATCH] gpio: msc313: remove kcalloc
2026-03-08 2:15 [PATCH] gpio: msc313: remove kcalloc Rosen Penev
@ 2026-03-08 5:59 ` Daniel Palmer
2026-03-09 0:06 ` Linus Walleij
1 sibling, 0 replies; 8+ messages in thread
From: Daniel Palmer @ 2026-03-08 5:59 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-gpio, linux-hardening, gustavoars, Romain Perier,
Linus Walleij, Bartosz Golaszewski,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
Hi Rosen,
On Sun, 8 Mar 2026 at 11:15, Rosen Penev <rosenp@gmail.com> wrote:
>
> Use a flexible array member to combine kzalloc and kcalloc.
Thanks for the patch. This looks good to me. If I get time I will
build and test this but I can see why it shouldn't work.
Acked-by: Daniel Palmer <daniel@thingy.jp>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] gpio: msc313: remove kcalloc
2026-03-08 2:15 [PATCH] gpio: msc313: remove kcalloc Rosen Penev
2026-03-08 5:59 ` Daniel Palmer
@ 2026-03-09 0:06 ` Linus Walleij
2026-03-09 1:27 ` Rosen Penev
1 sibling, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2026-03-09 0:06 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-gpio, Daniel Palmer, linux-hardening, gustavoars,
Romain Perier, Bartosz Golaszewski,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev <rosenp@gmail.com> wrote:
> Use a flexible array member to combine kzalloc and kcalloc.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
(...)
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] gpio: msc313: remove kcalloc
2026-03-09 0:06 ` Linus Walleij
@ 2026-03-09 1:27 ` Rosen Penev
2026-03-09 3:17 ` Gustavo A. R. Silva
2026-03-09 9:03 ` Bartosz Golaszewski
0 siblings, 2 replies; 8+ messages in thread
From: Rosen Penev @ 2026-03-09 1:27 UTC (permalink / raw)
To: Linus Walleij
Cc: linux-gpio, Daniel Palmer, linux-hardening, gustavoars,
Romain Perier, Bartosz Golaszewski,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
On Sun, Mar 8, 2026 at 5:06 PM Linus Walleij <linusw@kernel.org> wrote:
>
> On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev <rosenp@gmail.com> wrote:
>
> > Use a flexible array member to combine kzalloc and kcalloc.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> (...)
> > 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] gpio: msc313: remove kcalloc
2026-03-09 1:27 ` Rosen Penev
@ 2026-03-09 3:17 ` Gustavo A. R. Silva
2026-03-09 9:03 ` Bartosz Golaszewski
1 sibling, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2026-03-09 3:17 UTC (permalink / raw)
To: Rosen Penev, Linus Walleij
Cc: linux-gpio, Daniel Palmer, linux-hardening, gustavoars,
Romain Perier, Bartosz Golaszewski,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
On 3/9/26 10:27, Rosen Penev wrote:
> On Sun, Mar 8, 2026 at 5:06 PM Linus Walleij <linusw@kernel.org> wrote:
>>
>> On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev <rosenp@gmail.com> wrote:
>>
>>> Use a flexible array member to combine kzalloc and kcalloc.
>>>
>>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> (...)
>>> 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.
We actually have __counted_by_ptr().
-Gustavo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] gpio: msc313: remove kcalloc
2026-03-09 1:27 ` Rosen Penev
2026-03-09 3:17 ` Gustavo A. R. Silva
@ 2026-03-09 9:03 ` Bartosz Golaszewski
2026-03-09 22:00 ` Rosen Penev
1 sibling, 1 reply; 8+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 9:03 UTC (permalink / raw)
To: Rosen Penev
Cc: Linus Walleij, linux-gpio, Daniel Palmer, linux-hardening,
gustavoars, Romain Perier,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
On Mon, Mar 9, 2026 at 2:27 AM Rosen Penev <rosenp@gmail.com> wrote:
>
> On Sun, Mar 8, 2026 at 5:06 PM Linus Walleij <linusw@kernel.org> wrote:
> >
> > On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev <rosenp@gmail.com> wrote:
> >
> > > Use a flexible array member to combine kzalloc and kcalloc.
> > >
> > > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > (...)
> > > 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.
> >
This is a regular flexible array of u8. It should work fine with
__counted_by and I too am in favor of using it as it has become
standard for flexible arrays.
Bart
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] gpio: msc313: remove kcalloc
2026-03-09 9:03 ` Bartosz Golaszewski
@ 2026-03-09 22:00 ` Rosen Penev
2026-03-10 8:51 ` Bartosz Golaszewski
0 siblings, 1 reply; 8+ messages in thread
From: Rosen Penev @ 2026-03-09 22:00 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, linux-gpio, Daniel Palmer, linux-hardening,
gustavoars, Romain Perier,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
On Mon, Mar 9, 2026 at 2:03 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
>
> On Mon, Mar 9, 2026 at 2:27 AM Rosen Penev <rosenp@gmail.com> wrote:
> >
> > On Sun, Mar 8, 2026 at 5:06 PM Linus Walleij <linusw@kernel.org> wrote:
> > >
> > > On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev <rosenp@gmail.com> wrote:
> > >
> > > > Use a flexible array member to combine kzalloc and kcalloc.
> > > >
> > > > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > > (...)
> > > > 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.
> > >
>
> This is a regular flexible array of u8. It should work fine with
> __counted_by and I too am in favor of using it as it has become
> standard for flexible arrays.
That requires adding an extra variable in the struct.
>
> Bart
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] gpio: msc313: remove kcalloc
2026-03-09 22:00 ` Rosen Penev
@ 2026-03-10 8:51 ` Bartosz Golaszewski
0 siblings, 0 replies; 8+ messages in thread
From: Bartosz Golaszewski @ 2026-03-10 8:51 UTC (permalink / raw)
To: Rosen Penev
Cc: Linus Walleij, linux-gpio, Daniel Palmer, linux-hardening,
gustavoars, Romain Perier,
moderated list:ARM/MStar/Sigmastar Armv7 SoC support, open list
On Mon, Mar 9, 2026 at 11:00 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> On Mon, Mar 9, 2026 at 2:03 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
> >
> > On Mon, Mar 9, 2026 at 2:27 AM Rosen Penev <rosenp@gmail.com> wrote:
> > >
> > > On Sun, Mar 8, 2026 at 5:06 PM Linus Walleij <linusw@kernel.org> wrote:
> > > >
> > > > On Sun, Mar 8, 2026 at 3:15 AM Rosen Penev <rosenp@gmail.com> wrote:
> > > >
> > > > > Use a flexible array member to combine kzalloc and kcalloc.
> > > > >
> > > > > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > > > (...)
> > > > > 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.
> > > >
> >
> > This is a regular flexible array of u8. It should work fine with
> > __counted_by and I too am in favor of using it as it has become
> > standard for flexible arrays.
> That requires adding an extra variable in the struct.
That's ok, it's negligible and provides tangible advantages.
Please do the same for your other patches.
Bart
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-03-10 8:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-08 2:15 [PATCH] gpio: msc313: remove kcalloc Rosen Penev
2026-03-08 5:59 ` Daniel Palmer
2026-03-09 0:06 ` Linus Walleij
2026-03-09 1:27 ` Rosen Penev
2026-03-09 3:17 ` Gustavo A. R. Silva
2026-03-09 9:03 ` Bartosz Golaszewski
2026-03-09 22:00 ` Rosen Penev
2026-03-10 8:51 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox