[PATCH] media: platform: mtk-mdp3: Fix device reference leak in mdp_comp_init()

Nicolas Dufresne nicolas at ndufresne.ca
Tue Sep 29 13:44:22 PDT 2026


Le jeudi 17 septembre 2026 à 10:07 +0000, Wentao Liang a écrit :
> mdp_comp_init() takes a reference to the component platform device
> with of_find_device_by_node(), but the error path taken when the
> clock array cannot be allocated and the one taken for a component
> without a GCE EOF event return without dropping it.  The caller
> frees the mdp_comp in those cases, so the reference is leaked.
> 
> Release the reference on both error paths.
> 
> Fixes: c4320f9721fd ("media: platform: mtk-mdp3: dynamically allocate component clocks")
> Cc: stable at vger.kernel.org
> Signed-off-by: Wentao Liang <vulab at iscas.ac.cn>

Reviewed-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>

> ---
>  .../media/platform/mediatek/mdp3/mtk-mdp3-comp.c   | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> index 7fcb2fbdd64e..acb2758a7b42 100644
> --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> @@ -1730,6 +1730,7 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
>  	struct device *dev = &mdp->pdev->dev;
>  	struct platform_device *pdev_c;
>  	int clk_ofst;
> +	int ret;
>  	int i;
>  	s32 event;
>  
> @@ -1756,8 +1757,10 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
>  	comp->clk_num = mdp->mdp_data->comp_data[id].info.clk_num;
>  	comp->clks = devm_kzalloc(dev, sizeof(struct clk *) * comp->clk_num,
>  				  GFP_KERNEL);
> -	if (!comp->clks)
> -		return -ENOMEM;
> +	if (!comp->clks) {
> +		ret = -ENOMEM;
> +		goto err_put_device;
> +	}
>  
>  	clk_ofst = mdp->mdp_data->comp_data[id].info.clk_ofst;
>  
> @@ -1782,7 +1785,8 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
>  		if (of_property_read_u32_index(node, "mediatek,gce-events",
>  					       MDP_GCE_EVENT_EOF, &event)) {
>  			dev_err(dev, "Component id %d has no EOF\n", id);
> -			return -EINVAL;
> +			ret = -EINVAL;
> +			goto err_put_device;
>  		}
>  	} else {
>  		event = MDP_GCE_NO_EVENT;
> @@ -1791,6 +1795,10 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
>  	comp->gce_event[MDP_GCE_EVENT_EOF] = event;
>  
>  	return 0;
> +
> +err_put_device:
> +	put_device(&pdev_c->dev);
> +	return ret;
>  }
>  
>  static void mdp_comp_deinit(struct mdp_comp *comp)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-mediatek/attachments/20260929/7cb57b6b/attachment.sig>


More information about the Linux-mediatek mailing list