Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sun Ke <sunke32@huawei.com>
To: <mchehab@kernel.org>, <matthias.bgg@gmail.com>,
	<hverkuil-cisco@xs4all.nl>, <ping-hsun.wu@mediatek.com>,
	<daoyuan.huang@mediatek.com>, <moudy.ho@mediatek.com>
Cc: <linux-media@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>,
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH 2/3] media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on()
Date: Fri, 23 Sep 2022 14:25:05 +0800	[thread overview]
Message-ID: <38c78ee6-8b7e-34fb-1dc0-8b2d28acdd3d@huawei.com> (raw)
In-Reply-To: <20220902085820.3777360-3-sunke32@huawei.com>

ping...

在 2022/9/2 16:58, Sun Ke 写道:
> mdp_comp_clock_on will increase runtime PM usage counter,
> and mdp_comp_clock_off will decrease the runtime PM usage counter.
> so, if mdp_comp_clock_on failed after increment runtime PM usage
> counter, it should decrease it before return a error code.
> 
> pm_runtime_get_sync will increment pm usage counter even it failed.
> Forgetting to putting operation will result in reference leak here.
> Fix it by replacing it with pm_runtime_resume_and_get to keep usage
> counter balanced.
> 
> And if failed to enable clk, add pm_runtime_put() to decrease the
> runtime PM usage counter.
> 
> Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver")
> Signed-off-by: Sun Ke <sunke32@huawei.com>
> ---
>   drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> index 9a6ba5851ccb..d3eaf8884412 100644
> --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
> @@ -682,7 +682,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp)
>   	int i, ret;
>   
>   	if (comp->comp_dev) {
> -		ret = pm_runtime_get_sync(comp->comp_dev);
> +		ret = pm_runtime_resume_and_get(comp->comp_dev);
>   		if (ret < 0) {
>   			dev_err(dev,
>   				"Failed to get power, err %d. type:%d id:%d\n",
> @@ -699,6 +699,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp)
>   			dev_err(dev,
>   				"Failed to enable clk %d. type:%d id:%d\n",
>   				i, comp->type, comp->id);
> +			pm_runtime_put(comp->comp_dev);
>   			return ret;
>   		}
>   	}
> 


  reply	other threads:[~2022-09-23  6:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02  8:58 [PATCH 0/3] three fixes for mtk-mdp3 Sun Ke
2022-09-02  8:58 ` [PATCH 1/3] media: platform: mtk-mdp3: use devm_kfree to free memory allocated with devm_kmalloc() Sun Ke
2022-09-02  9:08   ` AngeloGioacchino Del Regno
2022-09-02  8:58 ` [PATCH 2/3] media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on() Sun Ke
2022-09-23  6:25   ` Sun Ke [this message]
2022-09-23 13:04     ` Hans Verkuil
2022-09-02  8:58 ` [PATCH 3/3] media: platform: mtk-mdp3: fix error return code in mdp_vpu_dev_init() Sun Ke
2022-09-02  9:10   ` AngeloGioacchino Del Regno
2022-09-02 10:15     ` Sun Ke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38c78ee6-8b7e-34fb-1dc0-8b2d28acdd3d@huawei.com \
    --to=sunke32@huawei.com \
    --cc=daoyuan.huang@mediatek.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=moudy.ho@mediatek.com \
    --cc=ping-hsun.wu@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox