diff mbox series

[1/3] drm/bridge: ti-sn65dsi86: Simplify using pm_runtime_resume_and_get()

Message ID 20231123175425.496956-2-u.kleine-koenig@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series drm/bridge: ti-sn65dsi86: Some updates | expand

Commit Message

Uwe Kleine-König Nov. 23, 2023, 5:54 p.m. UTC
pm_runtime_resume_and_get() already drops the runtime PM usage counter
in the error case. So a call to pm_runtime_put_sync() can be dropped.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Neil Armstrong Nov. 24, 2023, 8:48 a.m. UTC | #1
On 23/11/2023 18:54, Uwe Kleine-König wrote:
> pm_runtime_resume_and_get() already drops the runtime PM usage counter
> in the error case. So a call to pm_runtime_put_sync() can be dropped.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>   drivers/gpu/drm/bridge/ti-sn65dsi86.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> index c45c07840f64..5b8e1dfc458d 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> @@ -1413,11 +1413,9 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>   	int ret;
>   
>   	if (!pdata->pwm_enabled) {
> -		ret = pm_runtime_get_sync(pdata->dev);
> -		if (ret < 0) {
> -			pm_runtime_put_sync(pdata->dev);
> +		ret = pm_runtime_resume_and_get(pdata->dev);
> +		if (ret < 0)
>   			return ret;
> -		}
>   	}
>   
>   	if (state->enabled) {

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Doug Anderson Nov. 28, 2023, 1:13 a.m. UTC | #2
Hi,

On Thu, Nov 23, 2023 at 9:54 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> pm_runtime_resume_and_get() already drops the runtime PM usage counter
> in the error case. So a call to pm_runtime_put_sync() can be dropped.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/gpu/drm/bridge/ti-sn65dsi86.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Laurent Pinchart Nov. 29, 2023, 12:39 a.m. UTC | #3
Hi Uwe,

Thank you for the patch.

On Thu, Nov 23, 2023 at 06:54:27PM +0100, Uwe Kleine-König wrote:
> pm_runtime_resume_and_get() already drops the runtime PM usage counter
> in the error case. So a call to pm_runtime_put_sync() can be dropped.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

I wonder if checkpatch should warn about usage of pm_runtime_get_sync().

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/gpu/drm/bridge/ti-sn65dsi86.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> index c45c07840f64..5b8e1dfc458d 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> @@ -1413,11 +1413,9 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>  	int ret;
>  
>  	if (!pdata->pwm_enabled) {
> -		ret = pm_runtime_get_sync(pdata->dev);
> -		if (ret < 0) {
> -			pm_runtime_put_sync(pdata->dev);
> +		ret = pm_runtime_resume_and_get(pdata->dev);
> +		if (ret < 0)
>  			return ret;
> -		}
>  	}
>  
>  	if (state->enabled) {
Doug Anderson Nov. 29, 2023, 12:51 a.m. UTC | #4
Hi,

On Thu, Nov 23, 2023 at 9:54 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> pm_runtime_resume_and_get() already drops the runtime PM usage counter
> in the error case. So a call to pm_runtime_put_sync() can be dropped.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/gpu/drm/bridge/ti-sn65dsi86.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Pushed this patch to drm-misc-next:

c9d99c73940e drm/bridge: ti-sn65dsi86: Simplify using
pm_runtime_resume_and_get()
Uwe Kleine-König Nov. 29, 2023, 9:51 a.m. UTC | #5
Hello Laurent,

On Wed, Nov 29, 2023 at 02:39:55AM +0200, Laurent Pinchart wrote:
> On Thu, Nov 23, 2023 at 06:54:27PM +0100, Uwe Kleine-König wrote:
> > pm_runtime_resume_and_get() already drops the runtime PM usage counter
> > in the error case. So a call to pm_runtime_put_sync() can be dropped.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> I wonder if checkpatch should warn about usage of pm_runtime_get_sync().

It should not warn in general. There are cases where
pm_runtime_get_sync() is the right function to use. See for example
commit aec488051633 ("crypto: stm32 - Properly handle pm_runtime_get
failing").

Best regards
Uwe
Laurent Pinchart Nov. 29, 2023, 10:11 a.m. UTC | #6
Hi Uwe,

On Wed, Nov 29, 2023 at 10:51:37AM +0100, Uwe Kleine-König wrote:
> On Wed, Nov 29, 2023 at 02:39:55AM +0200, Laurent Pinchart wrote:
> > On Thu, Nov 23, 2023 at 06:54:27PM +0100, Uwe Kleine-König wrote:
> > > pm_runtime_resume_and_get() already drops the runtime PM usage counter
> > > in the error case. So a call to pm_runtime_put_sync() can be dropped.
> > > 
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > 
> > I wonder if checkpatch should warn about usage of pm_runtime_get_sync().
> 
> It should not warn in general. There are cases where
> pm_runtime_get_sync() is the right function to use. See for example

Sure, the function most likely has some valid use cases (otherwise it
should just be removed), but I think those are are a minority. I was
just thinking out loud anyway.

> commit aec488051633 ("crypto: stm32 - Properly handle pm_runtime_get
> failing").

I don't know much about that device, but wouldn't the best option be to
avoid resuming the device at remove time ? In any case, that's getting
out of topic for the sn65dsi86 :-)
Uwe Kleine-König Nov. 29, 2023, 1:55 p.m. UTC | #7
Hello Laurent,

On Wed, Nov 29, 2023 at 12:11:50PM +0200, Laurent Pinchart wrote:
> On Wed, Nov 29, 2023 at 10:51:37AM +0100, Uwe Kleine-König wrote:
> > On Wed, Nov 29, 2023 at 02:39:55AM +0200, Laurent Pinchart wrote:
> > > On Thu, Nov 23, 2023 at 06:54:27PM +0100, Uwe Kleine-König wrote:
> > > > pm_runtime_resume_and_get() already drops the runtime PM usage counter
> > > > in the error case. So a call to pm_runtime_put_sync() can be dropped.
> > > > 
> > > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > 
> > > I wonder if checkpatch should warn about usage of pm_runtime_get_sync().
> > 
> > It should not warn in general. There are cases where
> > pm_runtime_get_sync() is the right function to use. See for example
> 
> Sure, the function most likely has some valid use cases (otherwise it
> should just be removed), but I think those are are a minority. I was
> just thinking out loud anyway.
> 
> > commit aec488051633 ("crypto: stm32 - Properly handle pm_runtime_get
> > failing").
> 
> I don't know much about that device, but wouldn't the best option be to
> avoid resuming the device at remove time ? In any case, that's getting
> out of topic for the sn65dsi86 :-)

Agreed for off-topic, I adapted the Subject to make this more obvious
and added Greg and Rafael to Cc:.

Without waking the device in .remove() it's harder to properly free
resources. OTOH if you properly handle a failure to wake the device, you
cope for most of that difficulty already anyhow. Hmm.

One thing that makes this (IMHO) worse is that __device_release_driver()
calls pm_runtime_put_sync() just before device_remove() (which triggers
calling the driver's remove function). See
https://lore.kernel.org/linux-kernel/20230511073428.10264-1-u.kleine-koenig@pengutronix.de
for an earlier discussion about that topic.

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index c45c07840f64..5b8e1dfc458d 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -1413,11 +1413,9 @@  static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 	int ret;
 
 	if (!pdata->pwm_enabled) {
-		ret = pm_runtime_get_sync(pdata->dev);
-		if (ret < 0) {
-			pm_runtime_put_sync(pdata->dev);
+		ret = pm_runtime_resume_and_get(pdata->dev);
+		if (ret < 0)
 			return ret;
-		}
 	}
 
 	if (state->enabled) {