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

From: Lee Jones

Date: Fri Nov 27 2026 - 14:27:46 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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;
}
--
2.56.1.839.g22a8290db9-goog