[PATCH] clk: keystone: sci-clk: use devm_kmemdup_array() once more in ti_sci_scan_clocks_from_fw()
Andy Shevchenko
andriy.shevchenko at linux.intel.com
Fri Oct 31 07:43:42 PDT 2025
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
More information about the linux-arm-kernel
mailing list