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