linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/vc4: Fix pm_runtime_get_sync() error checking
@ 2022-04-12  7:04 Miaoqian Lin
  2022-04-19 12:44 ` Maxime Ripard
  0 siblings, 1 reply; 8+ messages in thread
From: Miaoqian Lin @ 2022-04-12  7:04 UTC (permalink / raw)
  To: Emma Anholt, Maxime Ripard, David Airlie, Daniel Vetter,
	Eric Anholt, dri-devel, linux-kernel
  Cc: linmq006

If the device is already in a runtime PM enabled state
pm_runtime_get_sync() will return 1, so a test for negative
value should be used to check for errors.

Fixes: 4078f5757144 ("drm/vc4: Add DSI driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/gpu/drm/vc4/vc4_dsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index 752f921735c6..26aa7d1fa421 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -847,7 +847,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	int ret;
 
 	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	if (ret < 0) {
 		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
 		return;
 	}
-- 
2.17.1


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

* Re: [PATCH] drm/vc4: Fix pm_runtime_get_sync() error checking
  2022-04-12  7:04 [PATCH] drm/vc4: Fix pm_runtime_get_sync() error checking Miaoqian Lin
@ 2022-04-19 12:44 ` Maxime Ripard
  2022-04-20  0:49   ` [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage Miaoqian Lin
  0 siblings, 1 reply; 8+ messages in thread
From: Maxime Ripard @ 2022-04-19 12:44 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Emma Anholt, David Airlie, Daniel Vetter, Eric Anholt, dri-devel,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]

Hi,

On Tue, Apr 12, 2022 at 07:04:57AM +0000, Miaoqian Lin wrote:
> If the device is already in a runtime PM enabled state
> pm_runtime_get_sync() will return 1, so a test for negative
> value should be used to check for errors.
> 
> Fixes: 4078f5757144 ("drm/vc4: Add DSI driver")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/gpu/drm/vc4/vc4_dsi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> index 752f921735c6..26aa7d1fa421 100644
> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> @@ -847,7 +847,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
>  	int ret;
>  
>  	ret = pm_runtime_get_sync(dev);
> -	if (ret) {
> +	if (ret < 0) {
>  		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
>  		return;
>  	}

We also don't put back our reference after an error. I think a better
fix would be to switch to pm_runtime_resume_and_get.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage
  2022-04-19 12:44 ` Maxime Ripard
@ 2022-04-20  0:49   ` Miaoqian Lin
  2022-04-20  7:51     ` Maxime Ripard
  0 siblings, 1 reply; 8+ messages in thread
From: Miaoqian Lin @ 2022-04-20  0:49 UTC (permalink / raw)
  To: Emma Anholt, Maxime Ripard, David Airlie, Daniel Vetter,
	Eric Anholt, dri-devel, linux-kernel
  Cc: linmq006

If the device is already in a runtime PM enabled state
pm_runtime_get_sync() will return 1, so a test for negative
value should be used to check for errors.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync()
fails, so use pm_runtime_resume_and_get() instead. this function
will handle this.

Fixes: 4078f5757144 ("drm/vc4: Add DSI driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
change in v2:
- switch to pm_runtime_resume_and_get() to fix refcount leak.
---
 drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index 752f921735c6..9d7ffaf6bc70 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	unsigned long phy_clock;
 	int ret;
 
-	ret = pm_runtime_get_sync(dev);
-	if (ret) {
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0) {
 		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
 		return;
 	}
-- 
2.17.1


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

* Re: [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage
  2022-04-20  0:49   ` [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage Miaoqian Lin
@ 2022-04-20  7:51     ` Maxime Ripard
  2022-04-20  8:05       ` Miaoqian Lin
  0 siblings, 1 reply; 8+ messages in thread
From: Maxime Ripard @ 2022-04-20  7:51 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Emma Anholt, David Airlie, Daniel Vetter, Eric Anholt, dri-devel,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1250 bytes --]

On Wed, Apr 20, 2022 at 12:49:48AM +0000, Miaoqian Lin wrote:
> If the device is already in a runtime PM enabled state
> pm_runtime_get_sync() will return 1, so a test for negative
> value should be used to check for errors.
> 
> Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync()
> fails, so use pm_runtime_resume_and_get() instead. this function
> will handle this.
> 
> Fixes: 4078f5757144 ("drm/vc4: Add DSI driver")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> change in v2:
> - switch to pm_runtime_resume_and_get() to fix refcount leak.
> ---
>  drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> index 752f921735c6..9d7ffaf6bc70 100644
> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> @@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
>  	unsigned long phy_clock;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(dev);
> -	if (ret) {
> +	ret = pm_runtime_resume_and_get(dev);
> +	if (ret < 0) {

pm_runtime_resume_and_get will return 0 on success, so the previous check was correct

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage
  2022-04-20  7:51     ` Maxime Ripard
@ 2022-04-20  8:05       ` Miaoqian Lin
  2022-04-20 13:28         ` Maxime Ripard
  0 siblings, 1 reply; 8+ messages in thread
From: Miaoqian Lin @ 2022-04-20  8:05 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: Emma Anholt, David Airlie, Daniel Vetter, Eric Anholt, dri-devel,
	linux-kernel


On 2022/4/20 15:51, Maxime Ripard wrote:
> On Wed, Apr 20, 2022 at 12:49:48AM +0000, Miaoqian Lin wrote:
>> If the device is already in a runtime PM enabled state
>> pm_runtime_get_sync() will return 1, so a test for negative
>> value should be used to check for errors.
>>
>> Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync()
>> fails, so use pm_runtime_resume_and_get() instead. this function
>> will handle this.
>>
>> Fixes: 4078f5757144 ("drm/vc4: Add DSI driver")
>> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
>> ---
>> change in v2:
>> - switch to pm_runtime_resume_and_get() to fix refcount leak.
>> ---
>>  drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
>> index 752f921735c6..9d7ffaf6bc70 100644
>> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
>> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
>> @@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
>>  	unsigned long phy_clock;
>>  	int ret;
>>  
>> -	ret = pm_runtime_get_sync(dev);
>> -	if (ret) {
>> +	ret = pm_runtime_resume_and_get(dev);
>> +	if (ret < 0) {
> pm_runtime_resume_and_get will return 0 on success, so the previous check was correct

previous check is for pm_runtime_get_sync() not for pm_runtime_resume_and_get (),

I switch to pm_runtime_resume_and_get() to fix the refcount leak bug at the same time.

Sure it's ok to use check if(ret) to check the retval, I just follow a more common way

for usage of pm_runtime_resume_and_get() in the codebase—— check ret<0

Since pm_runtime_resume_and_get() return negative error code.

> Maxime

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

* Re: [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage
  2022-04-20  8:05       ` Miaoqian Lin
@ 2022-04-20 13:28         ` Maxime Ripard
  2022-04-20 13:50           ` [PATCH v3] drm/vc4: Use pm_runtime_resume_and_get to fix " Miaoqian Lin
  0 siblings, 1 reply; 8+ messages in thread
From: Maxime Ripard @ 2022-04-20 13:28 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Emma Anholt, David Airlie, Daniel Vetter, Eric Anholt, dri-devel,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2051 bytes --]

On Wed, Apr 20, 2022 at 04:05:35PM +0800, Miaoqian Lin wrote:
> 
> On 2022/4/20 15:51, Maxime Ripard wrote:
> > On Wed, Apr 20, 2022 at 12:49:48AM +0000, Miaoqian Lin wrote:
> >> If the device is already in a runtime PM enabled state
> >> pm_runtime_get_sync() will return 1, so a test for negative
> >> value should be used to check for errors.
> >>
> >> Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync()
> >> fails, so use pm_runtime_resume_and_get() instead. this function
> >> will handle this.
> >>
> >> Fixes: 4078f5757144 ("drm/vc4: Add DSI driver")
> >> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> >> ---
> >> change in v2:
> >> - switch to pm_runtime_resume_and_get() to fix refcount leak.
> >> ---
> >>  drivers/gpu/drm/vc4/vc4_dsi.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> >> index 752f921735c6..9d7ffaf6bc70 100644
> >> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> >> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> >> @@ -846,8 +846,8 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
> >>  	unsigned long phy_clock;
> >>  	int ret;
> >>  
> >> -	ret = pm_runtime_get_sync(dev);
> >> -	if (ret) {
> >> +	ret = pm_runtime_resume_and_get(dev);
> >> +	if (ret < 0) {
> > pm_runtime_resume_and_get will return 0 on success, so the previous check was correct
> 
> previous check is for pm_runtime_get_sync() not for pm_runtime_resume_and_get (),
> 
> I switch to pm_runtime_resume_and_get() to fix the refcount leak bug at the same time.
> 
> Sure it's ok to use check if(ret) to check the retval, I just follow a more common way
> 
> for usage of pm_runtime_resume_and_get() in the codebase—— check ret<0
> 
> Since pm_runtime_resume_and_get() return negative error code.

If it ain't broke, don't fix it. The previous condition was working
perfectly fine to catch the errors from pm_runtime_resume_and_get,
there's no reason to change it.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* [PATCH v3] drm/vc4: Use pm_runtime_resume_and_get to fix pm_runtime_get_sync() usage
  2022-04-20 13:28         ` Maxime Ripard
@ 2022-04-20 13:50           ` Miaoqian Lin
  2022-04-21  7:17             ` (subset) " Maxime Ripard
  0 siblings, 1 reply; 8+ messages in thread
From: Miaoqian Lin @ 2022-04-20 13:50 UTC (permalink / raw)
  To: Emma Anholt, Maxime Ripard, David Airlie, Daniel Vetter,
	Eric Anholt, dri-devel, linux-kernel
  Cc: linmq006

If the device is already in a runtime PM enabled state
pm_runtime_get_sync() will return 1.

Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync()
fails, so use pm_runtime_resume_and_get() instead. this function
will handle this.

Fixes: 4078f5757144 ("drm/vc4: Add DSI driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
change in v2:
- switch to pm_runtime_resume_and_get() to fix refcount leak.
changes in v3:
- keep the original checking way for retval.
---
 drivers/gpu/drm/vc4/vc4_dsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index 752f921735c6..98308a17e4ed 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -846,7 +846,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
 	unsigned long phy_clock;
 	int ret;
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret) {
 		DRM_ERROR("Failed to runtime PM enable on DSI%d\n", dsi->variant->port);
 		return;
-- 
2.17.1


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

* Re: (subset) [PATCH v3] drm/vc4: Use pm_runtime_resume_and_get to fix pm_runtime_get_sync() usage
  2022-04-20 13:50           ` [PATCH v3] drm/vc4: Use pm_runtime_resume_and_get to fix " Miaoqian Lin
@ 2022-04-21  7:17             ` Maxime Ripard
  0 siblings, 0 replies; 8+ messages in thread
From: Maxime Ripard @ 2022-04-21  7:17 UTC (permalink / raw)
  To: dri-devel, Maxime Ripard, Miaoqian Lin, linux-kernel,
	Daniel Vetter, Eric Anholt, Emma Anholt, David Airlie
  Cc: Maxime Ripard

On Wed, 20 Apr 2022 21:50:07 +0800, Miaoqian Lin wrote:
> If the device is already in a runtime PM enabled state
> pm_runtime_get_sync() will return 1.
> 
> Also, we need to call pm_runtime_put_noidle() when pm_runtime_get_sync()
> fails, so use pm_runtime_resume_and_get() instead. this function
> will handle this.
> 
> [...]

Applied to drm/drm-misc (drm-misc-fixes).

Thanks!
Maxime

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

end of thread, other threads:[~2022-04-21  7:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12  7:04 [PATCH] drm/vc4: Fix pm_runtime_get_sync() error checking Miaoqian Lin
2022-04-19 12:44 ` Maxime Ripard
2022-04-20  0:49   ` [PATCH v2] drm/vc4: Fix pm_runtime_get_sync() usage Miaoqian Lin
2022-04-20  7:51     ` Maxime Ripard
2022-04-20  8:05       ` Miaoqian Lin
2022-04-20 13:28         ` Maxime Ripard
2022-04-20 13:50           ` [PATCH v3] drm/vc4: Use pm_runtime_resume_and_get to fix " Miaoqian Lin
2022-04-21  7:17             ` (subset) " Maxime Ripard

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).