summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Goodbody <[email protected]>2025-10-08 10:23:35 +0100
committerTom Rini <[email protected]>2025-10-16 15:02:14 -0600
commit4b8bc5af80f1637cd71a1b6a0dffa7588a03f27c (patch)
treecb375801cad9518a3843afe2c86c3392ab752823
parenta157a73720e242f4e16c81e64d36be9d284d2028 (diff)
ti_sci: Prevent memory leak
temp is assigned the pointer returned by malloc which is used without a NULL check and then never freed. Add a NULL check and ensure temp is freed on all return paths. This issue was found by Smatch. Reviewed-by: Udit Kumar <[email protected]> Signed-off-by: Andrew Goodbody <[email protected]> Reviewed-by: Nishanth Menon <[email protected]> Tested-by: Anshul Dalal <[email protected]>
-rw-r--r--drivers/firmware/ti_sci.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
index 8013afef304..2042d885837 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -3083,7 +3083,10 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
dev_err(dev, "%s resource type ids not available\n", of_prop);
return ERR_PTR(sets);
}
- temp = malloc(sets);
+ temp = devm_kmalloc(dev, sets, GFP_KERNEL);
+ if (!temp)
+ return ERR_PTR(-ENOMEM);
+
sets /= sizeof(u32);
res->sets = sets;
@@ -3123,6 +3126,7 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
return ERR_PTR(-ENOMEM);
}
+ devm_kfree(dev, temp);
if (valid_set)
return res;