diff mbox series

[v2] drm/vc4: Fix pm_runtime_get_sync() usage

Message ID 20220420004949.20508-1-linmq006@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm/vc4: Fix pm_runtime_get_sync() usage | expand

Commit Message

Miaoqian Lin April 20, 2022, 12:49 a.m. UTC
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(-)

Comments

Maxime Ripard April 20, 2022, 7:51 a.m. UTC | #1
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
Miaoqian Lin April 20, 2022, 8:05 a.m. UTC | #2
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
Maxime Ripard April 20, 2022, 1:28 p.m. UTC | #3
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
diff mbox series

Patch

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