From: Brian Masney <bmasney@redhat.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: linux-clk@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
Gregory Clement <gregory.clement@bootlin.com>,
Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"moderated list:ARM/Marvell Kirkwood and Armada 370, 375,
38x,..." <linux-arm-kernel@lists.infradead.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b"
<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] clk: kirkwood: use kzalloc_flex
Date: Mon, 30 Mar 2026 09:13:04 -0400 [thread overview]
Message-ID: <acp24GchNcb9iHXJ@redhat.com> (raw)
In-Reply-To: <20260326045555.240730-1-rosenp@gmail.com>
On Wed, Mar 25, 2026 at 09:55:55PM -0700, Rosen Penev wrote:
> Simplify allocation by using a flexible array member and kzalloc_flex to
> combine allocations.
>
> Add __counted_by for extra runtime analysis. Move counting variable
> assignment to right after allocation as required by __counted_by.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/clk/mvebu/kirkwood.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/clk/mvebu/kirkwood.c b/drivers/clk/mvebu/kirkwood.c
> index ed061d82fb65..fc2972538008 100644
> --- a/drivers/clk/mvebu/kirkwood.c
> +++ b/drivers/clk/mvebu/kirkwood.c
> @@ -253,8 +253,8 @@ struct clk_muxing_soc_desc {
>
> struct clk_muxing_ctrl {
> spinlock_t *lock;
> - struct clk **muxes;
> int num_muxes;
> + struct clk *muxes[] __counted_by(num_muxes);
> };
>
> static const char *powersave_parents[] = {
> @@ -297,21 +297,18 @@ static void __init kirkwood_clk_muxing_setup(struct device_node *np,
> if (WARN_ON(!base))
> return;
>
> - ctrl = kzalloc_obj(*ctrl);
> - if (WARN_ON(!ctrl))
> - goto ctrl_out;
> -
> - /* lock must already be initialized */
> - ctrl->lock = &ctrl_gating_lock;
> -
> /* Count, allocate, and register clock muxes */
> for (n = 0; desc[n].name;)
> n++;
>
> + ctrl = kzalloc_flex(*ctrl, muxes, n);
> + if (WARN_ON(!ctrl))
> + goto ctrl_out;
> +
> ctrl->num_muxes = n;
> - ctrl->muxes = kzalloc_objs(struct clk *, ctrl->num_muxes);
> - if (WARN_ON(!ctrl->muxes))
> - goto muxes_out;
Question from Sashiko:
https://sashiko.dev/#/patchset/20260326045555.240730-1-rosenp%40gmail.com
This isn't a bug, but since the goto muxes_out error path was removed here,
should the muxes_out label and its kfree(ctrl) be removed at the end of the
function?
They appear to be dead code now and might cause an unused label warning:
return;
muxes_out:
kfree(ctrl);
ctrl_out:
iounmap(base);
}
Brian
> +
> + /* lock must already be initialized */
> + ctrl->lock = &ctrl_gating_lock;
>
> for (n = 0; n < ctrl->num_muxes; n++) {
> ctrl->muxes[n] = clk_register_mux(NULL, desc[n].name,
> --
> 2.53.0
>
prev parent reply other threads:[~2026-03-30 13:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 4:55 [PATCH] clk: kirkwood: use kzalloc_flex Rosen Penev
2026-03-30 13:13 ` Brian Masney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=acp24GchNcb9iHXJ@redhat.com \
--to=bmasney@redhat.com \
--cc=andrew@lunn.ch \
--cc=gregory.clement@bootlin.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=rosenp@gmail.com \
--cc=sboyd@kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox