* [PATCH] mailbox: hi6220: kzalloc + kcalloc to kzalloc
@ 2026-03-11 0:35 Rosen Penev
2026-03-29 16:28 ` Jassi Brar
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-11 0:35 UTC (permalink / raw)
To: linux-kernel
Cc: Jassi Brar, Kees Cook, Gustavo A. R. Silva,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Reduce allocations to a single one by using a flexible array member.
Allows using __counted_by for extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/mailbox/hi6220-mailbox.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/mailbox/hi6220-mailbox.c b/drivers/mailbox/hi6220-mailbox.c
index f77741ce42e7..69d15b6283e9 100644
--- a/drivers/mailbox/hi6220-mailbox.c
+++ b/drivers/mailbox/hi6220-mailbox.c
@@ -79,12 +79,12 @@ struct hi6220_mbox {
/* region for mailbox */
void __iomem *base;
- unsigned int chan_num;
- struct hi6220_mbox_chan *mchan;
-
void *irq_map_chan[MBOX_CHAN_MAX];
struct mbox_chan *chan;
struct mbox_controller controller;
+
+ unsigned int chan_num;
+ struct hi6220_mbox_chan mchan[] __counted_by(chan_num);
};
static void mbox_set_state(struct hi6220_mbox *mbox,
@@ -267,16 +267,12 @@ static int hi6220_mbox_probe(struct platform_device *pdev)
struct hi6220_mbox *mbox;
int i, err;
- mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL);
+ mbox = devm_kzalloc(dev, struct_size(mbox, mchan, MBOX_CHAN_MAX), GFP_KERNEL);
if (!mbox)
return -ENOMEM;
- mbox->dev = dev;
mbox->chan_num = MBOX_CHAN_MAX;
- mbox->mchan = devm_kcalloc(dev,
- mbox->chan_num, sizeof(*mbox->mchan), GFP_KERNEL);
- if (!mbox->mchan)
- return -ENOMEM;
+ mbox->dev = dev;
mbox->chan = devm_kcalloc(dev,
mbox->chan_num, sizeof(*mbox->chan), GFP_KERNEL);
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mailbox: hi6220: kzalloc + kcalloc to kzalloc
2026-03-11 0:35 [PATCH] mailbox: hi6220: kzalloc + kcalloc to kzalloc Rosen Penev
@ 2026-03-29 16:28 ` Jassi Brar
0 siblings, 0 replies; 2+ messages in thread
From: Jassi Brar @ 2026-03-29 16:28 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-kernel, Kees Cook, Gustavo A. R. Silva,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Tue, Mar 10, 2026 at 7:36 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> Reduce allocations to a single one by using a flexible array member.
>
> Allows using __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/mailbox/hi6220-mailbox.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/mailbox/hi6220-mailbox.c b/drivers/mailbox/hi6220-mailbox.c
> index f77741ce42e7..69d15b6283e9 100644
> --- a/drivers/mailbox/hi6220-mailbox.c
> +++ b/drivers/mailbox/hi6220-mailbox.c
> @@ -79,12 +79,12 @@ struct hi6220_mbox {
> /* region for mailbox */
> void __iomem *base;
>
> - unsigned int chan_num;
> - struct hi6220_mbox_chan *mchan;
> -
> void *irq_map_chan[MBOX_CHAN_MAX];
> struct mbox_chan *chan;
> struct mbox_controller controller;
> +
> + unsigned int chan_num;
> + struct hi6220_mbox_chan mchan[] __counted_by(chan_num);
> };
>
> static void mbox_set_state(struct hi6220_mbox *mbox,
> @@ -267,16 +267,12 @@ static int hi6220_mbox_probe(struct platform_device *pdev)
> struct hi6220_mbox *mbox;
> int i, err;
>
> - mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL);
> + mbox = devm_kzalloc(dev, struct_size(mbox, mchan, MBOX_CHAN_MAX), GFP_KERNEL);
> if (!mbox)
> return -ENOMEM;
>
> - mbox->dev = dev;
> mbox->chan_num = MBOX_CHAN_MAX;
> - mbox->mchan = devm_kcalloc(dev,
> - mbox->chan_num, sizeof(*mbox->mchan), GFP_KERNEL);
> - if (!mbox->mchan)
> - return -ENOMEM;
> + mbox->dev = dev;
>
> mbox->chan = devm_kcalloc(dev,
> mbox->chan_num, sizeof(*mbox->chan), GFP_KERNEL);
> --
> 2.53.0
>
Applied to mailbox/for-next
Thanks
Jassi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-29 16:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 0:35 [PATCH] mailbox: hi6220: kzalloc + kcalloc to kzalloc Rosen Penev
2026-03-29 16:28 ` Jassi Brar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox