Re: [PATCH v2 2/3] firmware: qcom: scm: Fix reserved memory cleanup on probe failure

From: Konrad Dybcio

Date: Tue Jun 30 2026 - 06:08:31 EST


On 6/29/26 4:17 PM, Mukesh Ojha wrote:
> of_reserved_mem_device_init() adds an entry to a global list with no
> devres counterpart. If qcom_scm_probe() fails after the call the
> assignment is never cleaned up. A probe retry would add a duplicate
> entry, leaking the original one permanently.
>
> Add an err_rmem label that calls of_reserved_mem_device_release() and
> route all error paths after of_reserved_mem_device_init() through it.
> of_reserved_mem_device_release() is safe to call unconditionally as it
> simply walks an empty list when nothing was assigned.
>
> Fixes: a33b2579c8d3 ("firmware: qcom: scm: add support for SHM bridge memory carveout")
> Signed-off-by: Mukesh Ojha <mukesh.ojha@xxxxxxxxxxxxxxxx>
> ---
> drivers/firmware/qcom/qcom_scm.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
> index 464ae3b4ca43..f0e19fc314b4 100644
> --- a/drivers/firmware/qcom/qcom_scm.c
> +++ b/drivers/firmware/qcom/qcom_scm.c
> @@ -2785,9 +2785,11 @@ static int qcom_scm_probe(struct platform_device *pdev)
> "Failed to setup the reserved memory region for TZ mem\n");
>
> ret = qcom_tzmem_enable(scm->dev);
> - if (ret)
> - return dev_err_probe(scm->dev, ret,
> - "Failed to enable the TrustZone memory allocator\n");
> + if (ret) {
> + dev_err_probe(scm->dev, ret,
> + "Failed to enable the TrustZone memory allocator\n");

Assign ret = dev_err_probe to preserve the usefulness of this API

Alternatively, I cobbled this together, feel free to take it forward
(compile-tested only):