From: Rosen Penev <rosenp@gmail.com>
To: linux-clk@vger.kernel.org
Cc: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-arm-kernel@lists.infradead.org (moderated
list:ARM/Microchip (AT91) SoC support),
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: at91: use kzalloc_flex
Date: Thu, 12 Mar 2026 17:21:19 -0700 [thread overview]
Message-ID: <20260313002119.118962-1-rosenp@gmail.com> (raw)
Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation.
Add __counted_by to get extra runtime analysis. Move counting variable
assignment immediately after allocation as required by __counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/clk/at91/dt-compat.c | 15 ++++-----------
drivers/clk/at91/pmc.h | 2 +-
2 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/drivers/clk/at91/dt-compat.c b/drivers/clk/at91/dt-compat.c
index 5d543e807843..5c88cfafa31f 100644
--- a/drivers/clk/at91/dt-compat.c
+++ b/drivers/clk/at91/dt-compat.c
@@ -548,7 +548,6 @@ of_at91_clk_pll_get_characteristics(struct device_node *np)
int num_output;
u32 num_cells;
struct clk_range input;
- struct clk_range *output;
u8 *out = NULL;
u16 *icpll = NULL;
struct clk_pll_characteristics *characteristics;
@@ -568,13 +567,11 @@ of_at91_clk_pll_get_characteristics(struct device_node *np)
return NULL;
num_output /= num_cells;
- characteristics = kzalloc_obj(*characteristics);
+ characteristics = kzalloc_flex(*characteristics, output, num_output);
if (!characteristics)
return NULL;
- output = kzalloc_objs(*output, num_output);
- if (!output)
- goto out_free_characteristics;
+ characteristics->num_output = num_output;
if (num_cells > 2) {
out = kcalloc(num_output, sizeof(*out), GFP_KERNEL);
@@ -594,12 +591,12 @@ of_at91_clk_pll_get_characteristics(struct device_node *np)
"atmel,pll-clk-output-ranges",
offset, &tmp))
goto out_free_output;
- output[i].min = tmp;
+ charecteristics->output[i].min = tmp;
if (of_property_read_u32_index(np,
"atmel,pll-clk-output-ranges",
offset + 1, &tmp))
goto out_free_output;
- output[i].max = tmp;
+ charecteristics->output[i].max = tmp;
if (num_cells == 2)
continue;
@@ -621,8 +618,6 @@ of_at91_clk_pll_get_characteristics(struct device_node *np)
}
characteristics->input = input;
- characteristics->num_output = num_output;
- characteristics->output = output;
characteristics->out = out;
characteristics->icpll = icpll;
return characteristics;
@@ -630,8 +625,6 @@ of_at91_clk_pll_get_characteristics(struct device_node *np)
out_free_output:
kfree(icpll);
kfree(out);
- kfree(output);
-out_free_characteristics:
kfree(characteristics);
return NULL;
}
diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
index 543d7aee8d24..123050b4356d 100644
--- a/drivers/clk/at91/pmc.h
+++ b/drivers/clk/at91/pmc.h
@@ -75,12 +75,12 @@ extern const struct clk_pll_layout sama5d3_pll_layout;
struct clk_pll_characteristics {
struct clk_range input;
int num_output;
- const struct clk_range *output;
const struct clk_range *core_output;
u16 *icpll;
u8 *out;
u8 upll : 1;
u32 acr;
+ struct clk_range output[] __counted_by(num_output);
};
struct clk_programmable_layout {
--
2.53.0
reply other threads:[~2026-03-13 0:21 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=20260313002119.118962-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--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=nicolas.ferre@microchip.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