From: Brian Masney <bmasney@redhat.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: linux-clk@vger.kernel.org, Krzysztof Kozlowski <krzk@kernel.org>,
Sylwester Nawrocki <s.nawrocki@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
Alim Akhtar <alim.akhtar@samsung.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"open list:SAMSUNG SOC CLOCK DRIVERS"
<linux-samsung-soc@vger.kernel.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: [PATCHv2 1/3] clk: samsung: use kzalloc_flex
Date: Thu, 7 May 2026 19:34:41 -0400 [thread overview]
Message-ID: <af0hkVm0TQPTAiPd@redhat.com> (raw)
In-Reply-To: <20260506233833.178357-2-rosenp@gmail.com>
Hi Rosen,
On Wed, May 06, 2026 at 04:38:31PM -0700, Rosen Penev wrote:
> Simplify allocation by using kzalloc_flex with a flexible array member
> to combine allocations. samsung_clk_alloc_reg_dump is no longer needed
> for this struct but is needed elsewhere.
>
> Add __counted_by for extra runtime analysis. Move counting variable
> assignment after kzalloc_flex which does the same with GCC 15 and above.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/clk/samsung/clk.c | 11 ++++++-----
> drivers/clk/samsung/clk.h | 2 +-
> 2 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/clk/samsung/clk.c b/drivers/clk/samsung/clk.c
> index 91e5cdbc79d7..2895c77534ae 100644
> --- a/drivers/clk/samsung/clk.c
> +++ b/drivers/clk/samsung/clk.c
> @@ -430,21 +430,22 @@ void samsung_clk_extended_sleep_init(void __iomem *reg_base,
> unsigned long nr_rsuspend)
> {
> struct samsung_clock_reg_cache *reg_cache;
> + int i;
>
> - reg_cache = kzalloc_obj(struct samsung_clock_reg_cache);
> + reg_cache = kzalloc_flex(*reg_cache, rdump, nr_rdump);
> if (!reg_cache)
> panic("could not allocate register reg_cache.\n");
> - reg_cache->rdump = samsung_clk_alloc_reg_dump(rdump, nr_rdump);
samsung_clk_alloc_reg_dump() is used in three other places. Is it
possible to convert those 3 places in a similar fashion so that this
function can be dropped?
>
> - if (!reg_cache->rdump)
> - panic("could not allocate register dump storage.\n");
> + reg_cache->rd_num = nr_rdump;
> +
> + for (i = 0; i < nr_rdump; ++i)
> + reg_cache->rdump[i].offset = rdump[i];
>
> if (list_empty(&clock_reg_cache_list))
> register_syscore(&samsung_clk_syscore);
>
> reg_cache->reg_base = reg_base;
> reg_cache->sysreg = sysreg;
> - reg_cache->rd_num = nr_rdump;
> reg_cache->rsuspend = rsuspend;
> reg_cache->rsuspend_num = nr_rsuspend;
> list_add_tail(®_cache->node, &clock_reg_cache_list);
> diff --git a/drivers/clk/samsung/clk.h b/drivers/clk/samsung/clk.h
> index b1192ca03db5..098f27a6290d 100644
> --- a/drivers/clk/samsung/clk.h
> +++ b/drivers/clk/samsung/clk.h
> @@ -324,10 +324,10 @@ struct samsung_clock_reg_cache {
> struct list_head node;
> void __iomem *reg_base;
> struct regmap *sysreg;
> - struct samsung_clk_reg_dump *rdump;
> unsigned int rd_num;
> const struct samsung_clk_reg_dump *rsuspend;
> unsigned int rsuspend_num;
> + struct samsung_clk_reg_dump rdump[] __counted_by(rd_num);
Personally I think the rd_num should be above rdump so that they are
together.
Brian
next prev parent reply other threads:[~2026-05-07 23:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 23:38 [PATCHv2 0/3] clk: samsung: use kzalloc_flex Rosen Penev
2026-05-06 23:38 ` [PATCHv2 1/3] " Rosen Penev
2026-05-07 23:34 ` Brian Masney [this message]
2026-05-06 23:38 ` [PATCHv2 2/3] clk: samsung: cpu: " Rosen Penev
2026-05-06 23:38 ` [PATCHv2 3/3] clk: samsung: pll: " Rosen Penev
2026-05-07 8:32 ` [PATCHv2 0/3] clk: samsung: " Tudor Ambarus
2026-05-07 8:43 ` Rosen Penev
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=af0hkVm0TQPTAiPd@redhat.com \
--to=bmasney@redhat.com \
--cc=alim.akhtar@samsung.com \
--cc=cw00.choi@samsung.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=rosenp@gmail.com \
--cc=s.nawrocki@samsung.com \
--cc=sboyd@kernel.org \
/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