[PATCH 09/10] clk: keystone: sci-clk: Check allocation failure before copying clock array

Andrew Davis afd at ti.com
Thu Dec 3 08:21:45 PST 2026


On 11/27/26 1:25 PM, Lee Jones wrote:
> ti_sci_scan_clocks_from_fw() calls devm_kmalloc_objs() without checking
> for NULL before passing tmp_clks into memcpy(), and invokes memcpy()
> with a NULL source pointer on the initial iteration when max_clks is
> zero.
> 
> Return -ENOMEM if devm_kmalloc_objs() fails, and only copy and free the
> previous array when max_clks is non-zero.
> 
> Fixes: 3c13933c6033 ("clk: keystone: sci-clk: add support for dynamically probing clocks")
> Closes: https://sashiko.dev/#/bug/linux-4e2ecf16-17f1-4188-880c-c714a1bf588c
> Cc: stable at vger.kernel.org
> Signed-off-by: Lee Jones <lee at kernel.org>
> ---

LGTM,

Acked-by: Andrew Davis <afd at ti.com>

Side note though, this function `ti_sci_scan_clocks_from_fw()` is an unused
legacy function that was kept around for possible debugging. Now that AI
is finding bugs in it and causing churn, might be time to just delete the
whole function..

Andrew

>   drivers/clk/keystone/sci-clk.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c
> index 967f77900358..4cb1299cd49e 100644
> --- a/drivers/clk/keystone/sci-clk.c
> +++ b/drivers/clk/keystone/sci-clk.c
> @@ -495,9 +495,13 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
>   		if (num_clks == max_clks) {
>   			tmp_clks = devm_kmalloc_objs(dev, sci_clk,
>   						     max_clks + 64);
> -			memcpy(tmp_clks, clks, max_clks * sizeof(sci_clk));
> -			if (max_clks)
> +			if (!tmp_clks)
> +				return -ENOMEM;
> +			if (max_clks) {
> +				memcpy(tmp_clks, clks,
> +				       max_clks * sizeof(sci_clk));
>   				devm_kfree(dev, clks);
> +			}
>   			max_clks += 64;
>   			clks = tmp_clks;
>   		}




More information about the linux-arm-kernel mailing list