linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw()
@ 2025-10-31 14:33 Markus Elfring
  2025-10-31 14:43 ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2025-10-31 14:33 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel, Andy Shevchenko, Michael Turquette,
	Nishanth Menon, Raag Jadav, Santosh Shilimkar, Stephen Boyd,
	Tero Kristo
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 31 Oct 2025 15:20:22 +0100

* Reuse existing functionality from devm_kmemdup_array()
  instead of keeping duplicate source code.

* Prevent a null pointer dereference.


The source code was transformed by using the Coccinelle software.

Fixes: 3c13933c60338ce6fb2369bd0e93f91e52ddc17d ("clk: keystone: sci-clk: add support for dynamically probing clocks")
Cc: stable@vger.kernel.org
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/clk/keystone/sci-clk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c
index a4b42811de55..0c93c83d4776 100644
--- a/drivers/clk/keystone/sci-clk.c
+++ b/drivers/clk/keystone/sci-clk.c
@@ -456,12 +456,14 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
 		gap_size = 0;
 
 		if (num_clks == max_clks) {
-			tmp_clks = devm_kmalloc_array(dev, max_clks + 64,
-						      sizeof(sci_clk),
-						      GFP_KERNEL);
-			memcpy(tmp_clks, clks, max_clks * sizeof(sci_clk));
+			tmp_clks = devm_kmemdup_array(dev, clks, max_clks + 64,
+						      sizeof(sci_clk), GFP_KERNEL);
 			if (max_clks)
 				devm_kfree(dev, clks);
+
+			if (!tmp_clks)
+				return -ENOMEM;
+
 			max_clks += 64;
 			clks = tmp_clks;
 		}
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw()
  2025-10-31 14:33 [PATCH] clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw() Markus Elfring
@ 2025-10-31 14:43 ` Andy Shevchenko
  2025-10-31 15:06   ` Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2025-10-31 14:43 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-clk, linux-arm-kernel, Michael Turquette, Nishanth Menon,
	Raag Jadav, Santosh Shilimkar, Stephen Boyd, Tero Kristo, LKML,
	kernel-janitors

On Fri, Oct 31, 2025 at 03:33:24PM +0100, Markus Elfring wrote:
> 
> * Reuse existing functionality from devm_kmemdup_array()
>   instead of keeping duplicate source code.
> 
> * Prevent a null pointer dereference.
> 
> 
> The source code was transformed by using the Coccinelle software.
> 
> Fixes: 3c13933c60338ce6fb2369bd0e93f91e52ddc17d ("clk: keystone: sci-clk: add support for dynamically probing clocks")

Wrong format of Fixes tag, please keep the SHA at bare minumum.

...

>  		if (num_clks == max_clks) {
> -			tmp_clks = devm_kmalloc_array(dev, max_clks + 64,
> -						      sizeof(sci_clk),
> -						      GFP_KERNEL);
> -			memcpy(tmp_clks, clks, max_clks * sizeof(sci_clk));
> +			tmp_clks = devm_kmemdup_array(dev, clks, max_clks + 64,
> +						      sizeof(sci_clk), GFP_KERNEL);
>  			if (max_clks)
>  				devm_kfree(dev, clks);

> +			if (!tmp_clks)
> +				return -ENOMEM;

You haven't read the code, right?
This now will work differently. Would it be acceptable?

>  			max_clks += 64;
>  			clks = tmp_clks;
>  		}

-- 
With Best Regards,
Andy Shevchenko




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw()
  2025-10-31 14:43 ` Andy Shevchenko
@ 2025-10-31 15:06   ` Markus Elfring
  2025-11-03  7:48     ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2025-10-31 15:06 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-arm-kernel
  Cc: Michael Turquette, Nishanth Menon, Raag Jadav, Santosh Shilimkar,
	Stephen Boyd, Tero Kristo, LKML, kernel-janitors,
	Geert Uytterhoeven, Jonathan Corbet

>> Fixes: 3c13933c60338ce6fb2369bd0e93f91e52ddc17d ("clk: keystone: sci-clk: add support for dynamically probing clocks")
> 
> Wrong format of Fixes tag, please keep the SHA at bare minumum.

I got an other impression.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc3#n145

Would you find information from the commit 6356f18f09dc0781650c4f128ea48745fa48c415
("Align git commit ID abbreviation guidelines and checks") interesting also
for this technical detail?

Regards,
Markus


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw()
  2025-10-31 15:06   ` Markus Elfring
@ 2025-11-03  7:48     ` Andy Shevchenko
  2025-11-03  8:05       ` Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2025-11-03  7:48 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-clk, linux-arm-kernel, Michael Turquette, Nishanth Menon,
	Raag Jadav, Santosh Shilimkar, Stephen Boyd, Tero Kristo, LKML,
	kernel-janitors, Geert Uytterhoeven, Jonathan Corbet

On Fri, Oct 31, 2025 at 04:06:59PM +0100, Markus Elfring wrote:
> >> Fixes: 3c13933c60338ce6fb2369bd0e93f91e52ddc17d ("clk: keystone: sci-clk: add support for dynamically probing clocks")
> > 
> > Wrong format of Fixes tag, please keep the SHA at bare minumum.
> 
> I got an other impression.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc3#n145
> 
> Would you find information from the commit 6356f18f09dc0781650c4f128ea48745fa48c415
> ("Align git commit ID abbreviation guidelines and checks") interesting also
> for this technical detail?

Even the above mentioned commit doesn't do like you have done. 12+ doesn't mean
the full length. The rule of thumb is to use the minimum that doesn't give a
clash. And you may read the Linus' thoughts on the Geert's work. I.o.w. don't solve
the issue that doesn't exist.

-- 
With Best Regards,
Andy Shevchenko




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw()
  2025-11-03  7:48     ` Andy Shevchenko
@ 2025-11-03  8:05       ` Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2025-11-03  8:05 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-arm-kernel
  Cc: Michael Turquette, Nishanth Menon, Raag Jadav, Santosh Shilimkar,
	Stephen Boyd, Tero Kristo, LKML, kernel-janitors,
	Geert Uytterhoeven, Jonathan Corbet

>>>> Fixes: 3c13933c60338ce6fb2369bd0e93f91e52ddc17d ("clk: keystone: sci-clk: add support for dynamically probing clocks")

Will further adjustments become more helpful for the affected function implementation?

Regards,
Markus


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-03  8:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31 14:33 [PATCH] clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw() Markus Elfring
2025-10-31 14:43 ` Andy Shevchenko
2025-10-31 15:06   ` Markus Elfring
2025-11-03  7:48     ` Andy Shevchenko
2025-11-03  8:05       ` Markus Elfring

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).