[PATCH] remoteproc: scp: fix device reference leak on failed lookup

Mathieu Poirier mathieu.poirier at linaro.org
Wed Jul 8 10:07:52 PDT 2026


On Mon, Jul 06, 2026 at 08:56:14AM +0200, Johan Hovold wrote:
> Make sure to drop the reference taken to the SCP device when attempting
> to look up its driver data before the driver has been bound.
> 
> Note that holding a reference to a device does not prevent its driver
> data from going away.
> 
> Fixes: 63c13d61eafe ("remoteproc/mediatek: add SCP support for mt8183")
> Cc: stable at vger.kernel.org	# 5.6
> Cc: Erin Lo <erin.lo at mediatek.com>
> Signed-off-by: Johan Hovold <johan at kernel.org>
> ---
>  drivers/remoteproc/mtk_scp.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>

Applied.

Thanks,
Mathieu
 
> diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
> index 85a74c9ec521..436656bdfa8b 100644
> --- a/drivers/remoteproc/mtk_scp.c
> +++ b/drivers/remoteproc/mtk_scp.c
> @@ -36,6 +36,7 @@ struct mtk_scp *scp_get(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct device_node *scp_node;
>  	struct platform_device *scp_pdev;
> +	struct mtk_scp *scp;
>  
>  	scp_node = of_parse_phandle(dev->of_node, "mediatek,scp", 0);
>  	if (!scp_node) {
> @@ -51,7 +52,13 @@ struct mtk_scp *scp_get(struct platform_device *pdev)
>  		return NULL;
>  	}
>  
> -	return platform_get_drvdata(scp_pdev);
> +	scp = platform_get_drvdata(scp_pdev);
> +	if (!scp) {
> +		put_device(&scp_pdev->dev);
> +		return NULL;
> +	}
> +
> +	return scp;
>  }
>  EXPORT_SYMBOL_GPL(scp_get);
>  
> -- 
> 2.54.0
> 



More information about the Linux-mediatek mailing list