Thread (5 messages) 5 messages, 2 authors, 2025-11-03

Re: [PATCH] clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw()

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: 2025-10-31 14:43:51
Also in: kernel-janitors, linux-clk, lkml

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


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help