From: Sidharth Seela <sidharthseela@gmail.com>
To: claudiu.beznea@tuxon.dev, alexandre.belloni@bootlin.com,
nicolas.ferre@microchip.com, sboyd@kernel.org,
mturquette@baylibre.com
Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, david.hunter.linux@gmail.com,
skhan@linuxfoundation.org, khalid@kernel.org,
Sidharth Seela <sidharthseela@gmail.com>
Subject: [RFT PATCH v2] Use kmalloc_array() instead of kmalloc()
Date: Sun, 23 Nov 2025 12:39:06 +0530 [thread overview]
Message-ID: <20251123070905.93652-2-sidharthseela@gmail.com> (raw)
Refactor to new API, for cases with dynamic size calculations
inside kmalloc(). Such calculations were found using grep in the
sources. The patch compiles properly with multi_v7_defconfig
and multi_v5_defconfig and generates object files for the following
driver files.
Signed-off-by: Sidharth Seela <sidharthseela@gmail.com>
---
Changelog:
v1:https://lore.kernel.org/all/20250924145552.55058-1-sidharthseela@gmail.com/
-refactor code and run checkpatch.
-use sizeof(*ptr) not sizeof(void*).
-add RFT and the how the issue was found.
diff --git a/drivers/clk/at91/sam9x7.c b/drivers/clk/at91/sam9x7.c
index 89868a0aeaba..01bf557034e0 100644
--- a/drivers/clk/at91/sam9x7.c
+++ b/drivers/clk/at91/sam9x7.c
@@ -754,9 +754,9 @@ static void __init sam9x7_pmc_setup(struct device_node *np)
if (!sam9x7_pmc)
return;
- clk_mux_buffer = kmalloc(sizeof(void *) *
- (ARRAY_SIZE(sam9x7_gck)),
- GFP_KERNEL);
+ clk_mux_buffer = kmalloc_array(ARRAY_SIZE(sam9x7_gck),
+ sizeof(*clk_mux_buffer),
+ GFP_KERNEL);
if (!clk_mux_buffer)
goto err_free;
diff --git a/drivers/clk/at91/sama7d65.c b/drivers/clk/at91/sama7d65.c
index 7dee2b160ffb..91a5615f724a 100644
--- a/drivers/clk/at91/sama7d65.c
+++ b/drivers/clk/at91/sama7d65.c
@@ -1127,9 +1127,9 @@ static void __init sama7d65_pmc_setup(struct device_node *np)
if (!sama7d65_pmc)
return;
- alloc_mem = kmalloc(sizeof(void *) *
- (ARRAY_SIZE(sama7d65_mckx) + ARRAY_SIZE(sama7d65_gck)),
- GFP_KERNEL);
+ alloc_mem = kmalloc_array(ARRAY_SIZE(sama7d65_mckx) + ARRAY_SIZE(sama7d65_gck),
+ sizeof(*alloc_mem),
+ GFP_KERNEL);
if (!alloc_mem)
goto err_free;
diff --git a/drivers/clk/at91/sama7g5.c b/drivers/clk/at91/sama7g5.c
index 1340c2b00619..a12381f6c068 100644
--- a/drivers/clk/at91/sama7g5.c
+++ b/drivers/clk/at91/sama7g5.c
@@ -1004,9 +1004,9 @@ static void __init sama7g5_pmc_setup(struct device_node *np)
if (!sama7g5_pmc)
return;
- alloc_mem = kmalloc(sizeof(void *) *
- (ARRAY_SIZE(sama7g5_mckx) + ARRAY_SIZE(sama7g5_gck)),
- GFP_KERNEL);
+ alloc_mem = kmalloc_array(ARRAY_SIZE(sama7g5_mckx) + ARRAY_SIZE(sama7g5_gck),
+ sizeof(*alloc_mem),
+ GFP_KERNEL);
if (!alloc_mem)
goto err_free;
--
2.43.0
reply other threads:[~2025-11-23 7:10 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=20251123070905.93652-2-sidharthseela@gmail.com \
--to=sidharthseela@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=david.hunter.linux@gmail.com \
--cc=khalid@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=nicolas.ferre@microchip.com \
--cc=sboyd@kernel.org \
--cc=skhan@linuxfoundation.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;
as well as URLs for NNTP newsgroup(s).