From: Rosen Penev <rosenp@gmail.com>
To: linux-clk@vger.kernel.org
Cc: 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>,
linux-samsung-soc@vger.kernel.org (open list:SAMSUNG SOC CLOCK
DRIVERS), 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 3/3] clk: samsung: pll: use kzalloc_flex
Date: Wed, 1 Apr 2026 20:04:32 -0700 [thread overview]
Message-ID: <20260402030432.101066-4-rosenp@gmail.com> (raw)
In-Reply-To: <20260402030432.101066-1-rosenp@gmail.com>
Simplify allocation by using a flexible array member to combine
allocations and remove a kfree.
Use __counted_by for extra runtime analysis. Assign after allocation as
required by __counted_by.
Since rate_table is now a flexible array member, NULL checks don't work.
So use the counting variable to check allocation.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/clk/samsung/clk-pll.c | 56 ++++++++++++++++-------------------
1 file changed, 26 insertions(+), 30 deletions(-)
diff --git a/drivers/clk/samsung/clk-pll.c b/drivers/clk/samsung/clk-pll.c
index fdb84bcec912..e74552846ba3 100644
--- a/drivers/clk/samsung/clk-pll.c
+++ b/drivers/clk/samsung/clk-pll.c
@@ -28,7 +28,7 @@ struct samsung_clk_pll {
unsigned short lock_offs;
enum samsung_pll_type type;
unsigned int rate_count;
- const struct samsung_pll_rate_table *rate_table;
+ struct samsung_pll_rate_table rate_table[] __counted_by(rate_count);
};
#define to_clk_pll(_hw) container_of(_hw, struct samsung_clk_pll, hw)
@@ -1593,35 +1593,32 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
{
struct samsung_clk_pll *pll;
struct clk_init_data init;
- int ret, len;
+ unsigned int len = 0;
+ int ret;
- pll = kzalloc_obj(*pll);
+ if (pll_clk->rate_table) {
+ /* find count of rates in rate_table */
+ while (pll_clk->rate_table[len].rate != 0)
+ len++;
+ }
+
+ pll = kzalloc_flex(*pll, rate_table, len);
if (!pll) {
pr_err("%s: could not allocate pll clk %s\n",
__func__, pll_clk->name);
return;
}
+ pll->rate_count = len;
+ if (len)
+ memcpy(pll->rate_table, pll_clk->rate_table,
+ len * sizeof(*pll->rate_table));
+
init.name = pll_clk->name;
init.flags = pll_clk->flags;
init.parent_names = &pll_clk->parent_name;
init.num_parents = 1;
- if (pll_clk->rate_table) {
- /* find count of rates in rate_table */
- for (len = 0; pll_clk->rate_table[len].rate != 0; )
- len++;
-
- pll->rate_count = len;
- pll->rate_table = kmemdup_array(pll_clk->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__, pll_clk->name);
- }
-
switch (pll_clk->type) {
case pll_2126:
init.ops = &samsung_pll2126_clk_ops;
@@ -1640,7 +1637,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
case pll_a9fracm:
pll->enable_offs = PLL35XX_ENABLE_SHIFT;
pll->lock_offs = PLL35XX_LOCK_STAT_SHIFT;
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll35xx_clk_min_ops;
else
init.ops = &samsung_pll35xx_clk_ops;
@@ -1659,7 +1656,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
case pll_0732x:
pll->enable_offs = PLL0822X_ENABLE_SHIFT;
pll->lock_offs = PLL0822X_LOCK_STAT_SHIFT;
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll0822x_clk_min_ops;
else
init.ops = &samsung_pll0822x_clk_ops;
@@ -1669,7 +1666,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
break;
case pll_4502:
case pll_4508:
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll45xx_clk_min_ops;
else
init.ops = &samsung_pll45xx_clk_ops;
@@ -1679,7 +1676,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
case pll_2650:
pll->enable_offs = PLL36XX_ENABLE_SHIFT;
pll->lock_offs = PLL36XX_LOCK_STAT_SHIFT;
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll36xx_clk_min_ops;
else
init.ops = &samsung_pll36xx_clk_ops;
@@ -1687,7 +1684,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
case pll_0831x:
pll->enable_offs = PLL0831X_ENABLE_SHIFT;
pll->lock_offs = PLL0831X_LOCK_STAT_SHIFT;
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll0831x_clk_min_ops;
else
init.ops = &samsung_pll0831x_clk_ops;
@@ -1703,7 +1700,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
case pll_4650:
case pll_4650c:
case pll_1460x:
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll46xx_clk_min_ops;
else
init.ops = &samsung_pll46xx_clk_ops;
@@ -1712,19 +1709,19 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
init.ops = &samsung_pll2550x_clk_ops;
break;
case pll_2550xx:
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll2550xx_clk_min_ops;
else
init.ops = &samsung_pll2550xx_clk_ops;
break;
case pll_2650x:
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll2650x_clk_min_ops;
else
init.ops = &samsung_pll2650x_clk_ops;
break;
case pll_2650xx:
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll2650xx_clk_min_ops;
else
init.ops = &samsung_pll2650xx_clk_ops;
@@ -1734,7 +1731,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
init.ops = &samsung_pll531x_clk_ops;
break;
case pll_1031x:
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_pll1031x_clk_min_ops;
else
init.ops = &samsung_pll1031x_clk_ops;
@@ -1742,7 +1739,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
case pll_a9fraco:
pll->enable_offs = PLLA9FRACO_ENABLE_SHIFT;
pll->lock_offs = PLLA9FRACO_LOCK_STAT_SHIFT;
- if (!pll->rate_table)
+ if (!pll->rate_count)
init.ops = &samsung_a9fraco_clk_min_ops;
else
init.ops = &samsung_a9fraco_clk_ops;
@@ -1761,7 +1758,6 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
if (ret) {
pr_err("%s: failed to register pll clock %s : %d\n",
__func__, pll_clk->name, ret);
- kfree(pll->rate_table);
kfree(pll);
return;
}
--
2.53.0
prev parent reply other threads:[~2026-04-02 3:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 3:04 [PATCH 0/3] clk: samsung: use kzalloc_flex Rosen Penev
2026-04-02 3:04 ` [PATCH 1/3] " Rosen Penev
2026-04-02 3:11 ` Gustavo A. R. Silva
2026-04-02 3:04 ` [PATCH 2/3] clk: samsung: cpu: " Rosen Penev
2026-04-02 3:04 ` Rosen Penev [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=20260402030432.101066-4-rosenp@gmail.com \
--to=rosenp@gmail.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=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