kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] three fixes for mtk-mdp3
@ 2022-09-02  8:58 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
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sun Ke @ 2022-09-02  8:58 UTC (permalink / raw)
  To: mchehab, matthias.bgg, hverkuil-cisco, ping-hsun.wu,
	daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors, sunke32

three fixes for mtk-mdp3

Sun Ke (3):
  media: platform: mtk-mdp3: use devm_kfree to free memory allocated
    with devm_kmalloc()
  media: platform: mtk-mdp3: fix PM reference leak in
    mdp_comp_clock_on()
  media: platform: mtk-mdp3: fix error return code in mdp_vpu_dev_init()

 drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 7 ++++---
 drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c  | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] media: platform: mtk-mdp3: use devm_kfree to free memory allocated with devm_kmalloc()
  2022-09-02  8:58 [PATCH 0/3] three fixes for mtk-mdp3 Sun Ke
@ 2022-09-02  8:58 ` 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-02  8:58 ` [PATCH 3/3] media: platform: mtk-mdp3: fix error return code in mdp_vpu_dev_init() Sun Ke
  2 siblings, 1 reply; 9+ messages in thread
From: Sun Ke @ 2022-09-02  8:58 UTC (permalink / raw)
  To: mchehab, matthias.bgg, hverkuil-cisco, ping-hsun.wu,
	daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors, sunke32

comp is allocated with devm_kmalloc(), use devm_kfree to free it.

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 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
index e62abf3587bf..9a6ba5851ccb 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
@@ -869,7 +869,7 @@ static struct mdp_comp *mdp_comp_create(struct mdp_dev *mdp,
 
 	ret = mdp_comp_init(mdp, node, comp, id);
 	if (ret) {
-		kfree(comp);
+		devm_kfree(dev, comp);
 		return ERR_PTR(ret);
 	}
 	mdp->comp[id] = comp;
@@ -930,7 +930,7 @@ void mdp_comp_destroy(struct mdp_dev *mdp)
 		if (mdp->comp[i]) {
 			pm_runtime_disable(mdp->comp[i]->comp_dev);
 			mdp_comp_deinit(mdp->comp[i]);
-			kfree(mdp->comp[i]);
+			devm_kfree(mdp->comp[i]->comp_dev, mdp->comp[i]);
 			mdp->comp[i] = NULL;
 		}
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on()
  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  8:58 ` Sun Ke
  2022-09-23  6:25   ` Sun Ke
  2022-09-02  8:58 ` [PATCH 3/3] media: platform: mtk-mdp3: fix error return code in mdp_vpu_dev_init() Sun Ke
  2 siblings, 1 reply; 9+ messages in thread
From: Sun Ke @ 2022-09-02  8:58 UTC (permalink / raw)
  To: mchehab, matthias.bgg, hverkuil-cisco, ping-hsun.wu,
	daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors, sunke32

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;
 		}
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] media: platform: mtk-mdp3: fix error return code in mdp_vpu_dev_init()
  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  8:58 ` [PATCH 2/3] media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on() Sun Ke
@ 2022-09-02  8:58 ` Sun Ke
  2022-09-02  9:10   ` AngeloGioacchino Del Regno
  2 siblings, 1 reply; 9+ messages in thread
From: Sun Ke @ 2022-09-02  8:58 UTC (permalink / raw)
  To: mchehab, matthias.bgg, hverkuil-cisco, ping-hsun.wu,
	daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors, sunke32

If mdp_vpu_shared_mem_alloc failed, mdp_vpu_dev_init should return -ENOMEM.

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-vpu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
index 9f5844385c8f..078040b7f65e 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
@@ -175,6 +175,7 @@ int mdp_vpu_dev_init(struct mdp_vpu_dev *vpu, struct mtk_scp *scp,
 	mem_size = vpu_alloc_size;
 	if (mdp_vpu_shared_mem_alloc(vpu)) {
 		dev_err(&mdp->pdev->dev, "VPU memory alloc fail!");
+		err = -ENOMEM;
 		goto err_mem_alloc;
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] media: platform: mtk-mdp3: use devm_kfree to free memory allocated with devm_kmalloc()
  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
  0 siblings, 0 replies; 9+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-09-02  9:08 UTC (permalink / raw)
  To: Sun Ke, mchehab, matthias.bgg, hverkuil-cisco, ping-hsun.wu,
	daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors

Il 02/09/22 10:58, Sun Ke ha scritto:
> comp is allocated with devm_kmalloc(), use devm_kfree to free it.
> 
> Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver")
> Signed-off-by: Sun Ke <sunke32@huawei.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] media: platform: mtk-mdp3: fix error return code in mdp_vpu_dev_init()
  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
  0 siblings, 1 reply; 9+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-09-02  9:10 UTC (permalink / raw)
  To: Sun Ke, mchehab, matthias.bgg, hverkuil-cisco, ping-hsun.wu,
	daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors

Il 02/09/22 10:58, Sun Ke ha scritto:
> If mdp_vpu_shared_mem_alloc failed, mdp_vpu_dev_init should return -ENOMEM.
> 
> Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver")
> Signed-off-by: Sun Ke <sunke32@huawei.com>

Hello Sun,
thanks for the patch! However, someone else already sent the same fix and it's
in a better shape. Please look at [1].

Thanks,
Angelo

[1]: https://patchwork.kernel.org/project/linux-mediatek/patch/YxDGFMwyeNXFPaig@kili/

> ---
>   drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
> index 9f5844385c8f..078040b7f65e 100644
> --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
> +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
> @@ -175,6 +175,7 @@ int mdp_vpu_dev_init(struct mdp_vpu_dev *vpu, struct mtk_scp *scp,
>   	mem_size = vpu_alloc_size;
>   	if (mdp_vpu_shared_mem_alloc(vpu)) {
>   		dev_err(&mdp->pdev->dev, "VPU memory alloc fail!");
> +		err = -ENOMEM;
>   		goto err_mem_alloc;
>   	}
>   
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] media: platform: mtk-mdp3: fix error return code in mdp_vpu_dev_init()
  2022-09-02  9:10   ` AngeloGioacchino Del Regno
@ 2022-09-02 10:15     ` Sun Ke
  0 siblings, 0 replies; 9+ messages in thread
From: Sun Ke @ 2022-09-02 10:15 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno, mchehab, matthias.bgg,
	hverkuil-cisco, ping-hsun.wu, daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors



在 2022/9/2 17:10, AngeloGioacchino Del Regno 写道:
> Il 02/09/22 10:58, Sun Ke ha scritto:
>> If mdp_vpu_shared_mem_alloc failed, mdp_vpu_dev_init should return 
>> -ENOMEM.
>>
>> Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 
>> driver")
>> Signed-off-by: Sun Ke <sunke32@huawei.com>
> 
> Hello Sun,
> thanks for the patch! However, someone else already sent the same fix 
> and it's
> in a better shape. Please look at [1].
> 
> Thanks,
> Angelo
> 
> [1]: 
> https://patchwork.kernel.org/project/linux-mediatek/patch/YxDGFMwyeNXFPaig@kili/ 

Oh. I am late.

Thanks,
Sun Ke

> 
> 
>> ---
>>   drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c 
>> b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
>> index 9f5844385c8f..078040b7f65e 100644
>> --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
>> +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-vpu.c
>> @@ -175,6 +175,7 @@ int mdp_vpu_dev_init(struct mdp_vpu_dev *vpu, 
>> struct mtk_scp *scp,
>>       mem_size = vpu_alloc_size;
>>       if (mdp_vpu_shared_mem_alloc(vpu)) {
>>           dev_err(&mdp->pdev->dev, "VPU memory alloc fail!");
>> +        err = -ENOMEM;
>>           goto err_mem_alloc;
>>       }
>>
> 
> 
> .

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on()
  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
  2022-09-23 13:04     ` Hans Verkuil
  0 siblings, 1 reply; 9+ messages in thread
From: Sun Ke @ 2022-09-23  6:25 UTC (permalink / raw)
  To: mchehab, matthias.bgg, hverkuil-cisco, ping-hsun.wu,
	daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors

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;
>   		}
>   	}
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on()
  2022-09-23  6:25   ` Sun Ke
@ 2022-09-23 13:04     ` Hans Verkuil
  0 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2022-09-23 13:04 UTC (permalink / raw)
  To: Sun Ke, mchehab, matthias.bgg, ping-hsun.wu, daoyuan.huang, moudy.ho
  Cc: linux-media, linux-arm-kernel, linux-mediatek, kernel-janitors

It's in a pull request, waiting to be merged.

Regards,

	Hans

On 23/09/2022 08:25, Sun Ke wrote:
> 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;
>>           }
>>       }
>>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-09-23 13:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).