[PATCH v2 1/3] ti_sci: Prevent memory leak

Kumar, Udit u-kumar1 at ti.com
Tue Oct 7 16:10:19 CEST 2025


On 10/7/2025 5:34 PM, Andrew Goodbody wrote:
> 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.
>
> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> ---
>   drivers/firmware/ti_sci.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
> index 8013afef304dfb70ab14150ddc49d43ebebb5902..2042d88583766213e9d74dd17289cfd3562f0acb 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);

Reviewed-by: Udit Kumar <u-kumar1 at ti.com>


>   	if (valid_set)
>   		return res;
>   
>


More information about the U-Boot mailing list