From: Rosen Penev <rosenp@gmail.com>
To: linux-clk@vger.kernel.org
Cc: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-arm-kernel@lists.infradead.org (moderated list:ARM/TOSHIBA
VISCONTI ARCHITECTURE), linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] clk: visconti: pll: use kzalloc_flex
Date: Wed, 25 Mar 2026 21:23:17 -0700 [thread overview]
Message-ID: <20260326042317.122536-1-rosenp@gmail.com> (raw)
Simplify allocation by using a flexible array member and kzalloc_flex.
Add __counted_by for extra runtime analysis. Assign after allocation as
required by __counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/clk/visconti/pll.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/clk/visconti/pll.c b/drivers/clk/visconti/pll.c
index 6fd02c4b641e..ca29d12f9316 100644
--- a/drivers/clk/visconti/pll.c
+++ b/drivers/clk/visconti/pll.c
@@ -21,9 +21,9 @@ struct visconti_pll {
void __iomem *pll_base;
spinlock_t *lock;
unsigned long flags;
- const struct visconti_pll_rate_table *rate_table;
size_t rate_count;
struct visconti_pll_provider *ctx;
+ struct visconti_pll_rate_table rate_table[] __counted_by(rate_count);
};
#define PLL_CONF_REG 0x0000
@@ -255,10 +255,6 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx,
size_t len;
int ret;
- pll = kzalloc_obj(*pll);
- if (!pll)
- return ERR_PTR(-ENOMEM);
-
init.name = name;
init.flags = CLK_IGNORE_UNUSED;
init.parent_names = &parent_name;
@@ -266,11 +262,13 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx,
for (len = 0; rate_table[len].rate != 0; )
len++;
+
+ pll = kzalloc_flex(*pll, rate_table, len);
+ if (!pll)
+ return ERR_PTR(-ENOMEM);
+
pll->rate_count = len;
- pll->rate_table = kmemdup_array(rate_table,
- pll->rate_count, sizeof(*pll->rate_table),
- GFP_KERNEL);
- WARN(!pll->rate_table, "%s: could not allocate rate table for %s\n", __func__, name);
+ memcpy(pll->rate_table, rate_table, len * sizeof(*pll->rate_table));
init.ops = &visconti_pll_ops;
pll->hw.init = &init;
@@ -282,7 +280,6 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx,
ret = clk_hw_register(NULL, &pll->hw);
if (ret) {
pr_err("failed to register pll clock %s : %d\n", name, ret);
- kfree(pll->rate_table);
kfree(pll);
pll_hw_clk = ERR_PTR(ret);
}
--
2.53.0
reply other threads:[~2026-03-26 4:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260326042317.122536-1-rosenp@gmail.com \
--to=rosenp@gmail.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=nobuhiro.iwamatsu.x90@mail.toshiba \
--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