* Re: [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming
2020-11-02 14:26 [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming Zhang Qilong
@ 2020-11-02 14:18 ` Maxime Ripard
2020-11-02 14:39 ` 答复: " zhangqilong
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Maxime Ripard @ 2020-11-02 14:18 UTC (permalink / raw)
To: Zhang Qilong; +Cc: devel, gregkh, paul.kocialkowski, wens, mchehab, linux-media
[-- Attachment #1.1: Type: text/plain, Size: 526 bytes --]
On Mon, Nov 02, 2020 at 10:26:22PM +0800, Zhang Qilong wrote:
> pm_runtime_get_sync will increment pm usage counter even it
> failed. Forgetting to pm_runtime_put_noidle will result in
> reference leak in cedrus_start_streaming. We should fix it.
>
> Fixes: d5aecd289babf ("media: cedrus: Implement runtime PM")
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Shouldn't we fix pm_runtime_get_sync instead then? It seems that most of
the callers get this wrong, and that's definitely non-obvious.
Maxime
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 169 bytes --]
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming
@ 2020-11-02 14:26 Zhang Qilong
2020-11-02 14:18 ` Maxime Ripard
0 siblings, 1 reply; 7+ messages in thread
From: Zhang Qilong @ 2020-11-02 14:26 UTC (permalink / raw)
To: mripard, paul.kocialkowski, mchehab, wens; +Cc: devel, gregkh, linux-media
pm_runtime_get_sync will increment pm usage counter even it
failed. Forgetting to pm_runtime_put_noidle will result in
reference leak in cedrus_start_streaming. We should fix it.
Fixes: d5aecd289babf ("media: cedrus: Implement runtime PM")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
drivers/staging/media/sunxi/cedrus/cedrus_video.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index 667b86dde1ee..911f607d9b09 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -479,8 +479,10 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
ret = pm_runtime_get_sync(dev->dev);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(dev->dev);
goto err_cleanup;
+ }
if (dev->dec_ops[ctx->current_codec]->start) {
ret = dev->dec_ops[ctx->current_codec]->start(ctx);
--
2.17.1
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* 答复: [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming
2020-11-02 14:18 ` Maxime Ripard
@ 2020-11-02 14:39 ` zhangqilong
2020-11-02 15:12 ` Dan Carpenter
2020-11-04 11:39 ` Hans Verkuil
2 siblings, 0 replies; 7+ messages in thread
From: zhangqilong @ 2020-11-02 14:39 UTC (permalink / raw)
To: Maxime Ripard
Cc: devel, gregkh, paul.kocialkowski, wens, mchehab, linux-media
Hi
>
> On Mon, Nov 02, 2020 at 10:26:22PM +0800, Zhang Qilong wrote:
> > pm_runtime_get_sync will increment pm usage counter even it failed.
> > Forgetting to pm_runtime_put_noidle will result in reference leak in
> > cedrus_start_streaming. We should fix it.
> >
> > Fixes: d5aecd289babf ("media: cedrus: Implement runtime PM")
> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
>
> Shouldn't we fix pm_runtime_get_sync instead then? It seems that most of the
> callers get this wrong, and that's definitely non-obvious.
>
I have ever thought to fix fix pm_runtime_get_sync, then I went to read the comment on this function, and found that this is what the author intended to do(comment: The possible return values of this function are the same as for pm_runtime_resume() and the runtime PM usage counter of @dev remains incremented in all cases, even if it returns an error code). On the other hand, I found that the number of callers that getting this right is much bigger than getting this wrong even many callers get wrong. So I submit server patches to fix them as I could.
Thanks, best wish!
Zhang Qilong
> Maxime
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming
2020-11-02 14:18 ` Maxime Ripard
2020-11-02 14:39 ` 答复: " zhangqilong
@ 2020-11-02 15:12 ` Dan Carpenter
2020-11-04 11:39 ` Hans Verkuil
2 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2020-11-02 15:12 UTC (permalink / raw)
To: Maxime Ripard
Cc: devel, gregkh, Zhang Qilong, paul.kocialkowski, wens, mchehab,
linux-media
On Mon, Nov 02, 2020 at 03:18:38PM +0100, Maxime Ripard wrote:
> On Mon, Nov 02, 2020 at 10:26:22PM +0800, Zhang Qilong wrote:
> > pm_runtime_get_sync will increment pm usage counter even it
> > failed. Forgetting to pm_runtime_put_noidle will result in
> > reference leak in cedrus_start_streaming. We should fix it.
> >
> > Fixes: d5aecd289babf ("media: cedrus: Implement runtime PM")
> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
>
> Shouldn't we fix pm_runtime_get_sync instead then? It seems that most of
> the callers get this wrong, and that's definitely non-obvious.
>
> Maxime
The other bug that people run into is that pm_runtime_get_sync() can
return 1 on success.
drivers/spi/spi-img-spfi.c:734 img_spfi_resume() warn: pm_runtime_get_sync() also returns 1 on success
drivers/mfd/arizona-core.c:49 arizona_clk32k_enable() warn: pm_runtime_get_sync() also returns 1 on success
drivers/usb/dwc3/dwc3-pci.c:212 dwc3_pci_resume_work() warn: pm_runtime_get_sync() also returns 1 on success
drivers/input/keyboard/omap4-keypad.c:279 omap4_keypad_probe() warn: pm_runtime_get_sync() also returns 1 on success
drivers/gpu/drm/vc4/vc4_dsi.c:839 vc4_dsi_encoder_enable() warn: pm_runtime_get_sync() also returns 1 on success
drivers/gpu/drm/i915/selftests/mock_gem_device.c:157 mock_gem_device() warn: 'pm_runtime_get_sync(&pdev->dev)' returns positive and negative
drivers/watchdog/rti_wdt.c:230 rti_wdt_probe() warn: pm_runtime_get_sync() also returns 1 on success
drivers/media/platform/exynos4-is/mipi-csis.c:513 s5pcsis_s_stream() warn: pm_runtime_get_sync() also returns 1 on success
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c:89 mtk_vcodec_dec_pw_on() warn: pm_runtime_get_sync() also returns 1 on success
drivers/media/platform/ti-vpe/cal.c:794 cal_probe() warn: pm_runtime_get_sync() also returns 1 on success
drivers/media/platform/ti-vpe/vpe.c:2478 vpe_runtime_get() warn: pm_runtime_get_sync() also returns 1 on success
drivers/media/i2c/smiapp/smiapp-core.c:1529 smiapp_pm_get_init() warn: pm_runtime_get_sync() also returns 1 on success
I don't really understand the point of incrementing the counter on
failure well enough to write a check for this...
regards,
dan carpenter
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming
2020-11-02 14:18 ` Maxime Ripard
2020-11-02 14:39 ` 答复: " zhangqilong
2020-11-02 15:12 ` Dan Carpenter
@ 2020-11-04 11:39 ` Hans Verkuil
2020-11-05 8:06 ` 答复: " zhangqilong
2020-11-05 10:41 ` Dan Carpenter
2 siblings, 2 replies; 7+ messages in thread
From: Hans Verkuil @ 2020-11-04 11:39 UTC (permalink / raw)
To: Maxime Ripard, Zhang Qilong
Cc: devel, gregkh, paul.kocialkowski, wens, mchehab, linux-media
On 02/11/2020 15:18, Maxime Ripard wrote:
> On Mon, Nov 02, 2020 at 10:26:22PM +0800, Zhang Qilong wrote:
>> pm_runtime_get_sync will increment pm usage counter even it
>> failed. Forgetting to pm_runtime_put_noidle will result in
>> reference leak in cedrus_start_streaming. We should fix it.
>>
>> Fixes: d5aecd289babf ("media: cedrus: Implement runtime PM")
>> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
>
> Shouldn't we fix pm_runtime_get_sync instead then? It seems that most of
> the callers get this wrong, and that's definitely non-obvious.
It's been discussed before, but nobody stepped up to address this
issue. In the end I decided to just accept media patches that fix this
in the drivers rather than waiting for some mythical future core fix.
Nor do I think that you can just 'fix' pm_runtime_get_sync, since
then you will get cases where pm_runtime_put is called once too
often.
Regards,
Hans
>
> Maxime
>
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* 答复: [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming
2020-11-04 11:39 ` Hans Verkuil
@ 2020-11-05 8:06 ` zhangqilong
2020-11-05 10:41 ` Dan Carpenter
1 sibling, 0 replies; 7+ messages in thread
From: zhangqilong @ 2020-11-05 8:06 UTC (permalink / raw)
To: Hans Verkuil, Maxime Ripard
Cc: devel, gregkh, paul.kocialkowski, wens, mchehab, linux-media
> On 02/11/2020 15:18, Maxime Ripard wrote:
> > On Mon, Nov 02, 2020 at 10:26:22PM +0800, Zhang Qilong wrote:
> >> pm_runtime_get_sync will increment pm usage counter even it failed.
> >> Forgetting to pm_runtime_put_noidle will result in reference leak in
> >> cedrus_start_streaming. We should fix it.
> >>
> >> Fixes: d5aecd289babf ("media: cedrus: Implement runtime PM")
> >> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> >
> > Shouldn't we fix pm_runtime_get_sync instead then? It seems that most
> > of the callers get this wrong, and that's definitely non-obvious.
>
> It's been discussed before, but nobody stepped up to address this issue. In the
> end I decided to just accept media patches that fix this in the drivers rather
> than waiting for some mythical future core fix.
>
> Nor do I think that you can just 'fix' pm_runtime_get_sync, since then you will
> get cases where pm_runtime_put is called once too often.
>
Thanks for your nice comment, if any updates occur about pm_runtime_get_sync, I will pay attention to it.
Thanks, best wish,
Zhang Qilong
> Regards,
>
> Hans
>
> >
> > Maxime
> >
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming
2020-11-04 11:39 ` Hans Verkuil
2020-11-05 8:06 ` 答复: " zhangqilong
@ 2020-11-05 10:41 ` Dan Carpenter
1 sibling, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2020-11-05 10:41 UTC (permalink / raw)
To: Hans Verkuil
Cc: devel, gregkh, Zhang Qilong, paul.kocialkowski, wens,
Maxime Ripard, mchehab, linux-media
On Wed, Nov 04, 2020 at 12:39:11PM +0100, Hans Verkuil wrote:
> On 02/11/2020 15:18, Maxime Ripard wrote:
> > On Mon, Nov 02, 2020 at 10:26:22PM +0800, Zhang Qilong wrote:
> >> pm_runtime_get_sync will increment pm usage counter even it
> >> failed. Forgetting to pm_runtime_put_noidle will result in
> >> reference leak in cedrus_start_streaming. We should fix it.
> >>
> >> Fixes: d5aecd289babf ("media: cedrus: Implement runtime PM")
> >> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> >
> > Shouldn't we fix pm_runtime_get_sync instead then? It seems that most of
> > the callers get this wrong, and that's definitely non-obvious.
>
> It's been discussed before, but nobody stepped up to address this
> issue. In the end I decided to just accept media patches that fix this
> in the drivers rather than waiting for some mythical future core fix.
>
> Nor do I think that you can just 'fix' pm_runtime_get_sync, since
> then you will get cases where pm_runtime_put is called once too
> often.
Someone could easily add a helper function. The only complication is
thinking of the correct name.
regards,
dan carpenter
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-11-05 10:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02 14:26 [PATCH -next] media: cedrus: fix reference leak in cedrus_start_streaming Zhang Qilong
2020-11-02 14:18 ` Maxime Ripard
2020-11-02 14:39 ` 答复: " zhangqilong
2020-11-02 15:12 ` Dan Carpenter
2020-11-04 11:39 ` Hans Verkuil
2020-11-05 8:06 ` 答复: " zhangqilong
2020-11-05 10:41 ` Dan Carpenter
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).