LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] drm/brdige: analogix_dp: Grab runtime PM reference for DP-AUX
@ 2021-09-29 21:41 Brian Norris
  2021-10-01 20:37 ` Sean Paul
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Norris @ 2021-09-29 21:41 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong
  Cc: dri-devel, linux-rockchip, Laurent Pinchart, linux-kernel,
	Jonas Karlman, Jernej Skrabec, Brian Norris, stable,
	Tomeu Vizoso

If the display is not enable()d, then we aren't holding a runtime PM
reference here. Thus, it's easy to accidentally cause a hang, if user
space is poking around at /dev/drm_dp_aux0 at the "wrong" time.

Let's get the panel and PM state right before trying to talk AUX.

Fixes: 0d97ad03f422 ("drm/bridge: analogix_dp: Remove duplicated code")
Cc: <stable@vger.kernel.org>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 .../gpu/drm/bridge/analogix/analogix_dp_core.c  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
index b7d2e4449cfa..a1b553904b85 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
@@ -1632,8 +1632,23 @@ static ssize_t analogix_dpaux_transfer(struct drm_dp_aux *aux,
 				       struct drm_dp_aux_msg *msg)
 {
 	struct analogix_dp_device *dp = to_dp(aux);
+	int ret, ret2;
 
-	return analogix_dp_transfer(dp, msg);
+	ret = analogix_dp_prepare_panel(dp, true, false);
+	if (ret) {
+		DRM_DEV_ERROR(dp->dev, "Failed to prepare panel (%d)\n", ret);
+		return ret;
+	}
+
+	pm_runtime_get_sync(dp->dev);
+	ret = analogix_dp_transfer(dp, msg);
+	pm_runtime_put(dp->dev);
+
+	ret2 = analogix_dp_prepare_panel(dp, false, false);
+	if (ret2)
+		DRM_DEV_ERROR(dp->dev, "Failed to unprepare panel (%d)\n", ret2);
+
+	return ret;
 }
 
 struct analogix_dp_device *
-- 
2.33.0.685.g46640cef36-goog


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

* Re: [PATCH] drm/brdige: analogix_dp: Grab runtime PM reference for DP-AUX
  2021-09-29 21:41 [PATCH] drm/brdige: analogix_dp: Grab runtime PM reference for DP-AUX Brian Norris
@ 2021-10-01 20:37 ` Sean Paul
  2021-10-01 21:23   ` Brian Norris
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Paul @ 2021-10-01 20:37 UTC (permalink / raw)
  To: Brian Norris
  Cc: Andrzej Hajda, Neil Armstrong, dri-devel, linux-rockchip,
	Laurent Pinchart, linux-kernel, Jonas Karlman, Jernej Skrabec,
	stable, Tomeu Vizoso

On Wed, Sep 29, 2021 at 02:41:03PM -0700, Brian Norris wrote:
> If the display is not enable()d, then we aren't holding a runtime PM
> reference here. Thus, it's easy to accidentally cause a hang, if user
> space is poking around at /dev/drm_dp_aux0 at the "wrong" time.
> 
> Let's get the panel and PM state right before trying to talk AUX.
> 
> Fixes: 0d97ad03f422 ("drm/bridge: analogix_dp: Remove duplicated code")
> Cc: <stable@vger.kernel.org>
> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
> 
>  .../gpu/drm/bridge/analogix/analogix_dp_core.c  | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> index b7d2e4449cfa..a1b553904b85 100644
> --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> @@ -1632,8 +1632,23 @@ static ssize_t analogix_dpaux_transfer(struct drm_dp_aux *aux,
>  				       struct drm_dp_aux_msg *msg)
>  {
>  	struct analogix_dp_device *dp = to_dp(aux);
> +	int ret, ret2;
>  
> -	return analogix_dp_transfer(dp, msg);
> +	ret = analogix_dp_prepare_panel(dp, true, false);
> +	if (ret) {
> +		DRM_DEV_ERROR(dp->dev, "Failed to prepare panel (%d)\n", ret);

s/DRM_DEV_ERROR/drm_err/

> +		return ret;
> +	}
> +
> +	pm_runtime_get_sync(dp->dev);
> +	ret = analogix_dp_transfer(dp, msg);
> +	pm_runtime_put(dp->dev);
> +
> +	ret2 = analogix_dp_prepare_panel(dp, false, false);
> +	if (ret2)
> +		DRM_DEV_ERROR(dp->dev, "Failed to unprepare panel (%d)\n", ret2);

What's the reasoning for not propagating unprepare failures? I feel like that
should be fair game.

> +
> +	return ret;
>  }
>  
>  struct analogix_dp_device *
> -- 
> 2.33.0.685.g46640cef36-goog
> 

-- 
Sean Paul, Software Engineer, Google / Chromium OS

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

* Re: [PATCH] drm/brdige: analogix_dp: Grab runtime PM reference for DP-AUX
  2021-10-01 20:37 ` Sean Paul
@ 2021-10-01 21:23   ` Brian Norris
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Norris @ 2021-10-01 21:23 UTC (permalink / raw)
  To: Sean Paul
  Cc: Andrzej Hajda, Neil Armstrong, dri-devel,
	open list:ARM/Rockchip SoC...,
	Laurent Pinchart, Linux Kernel, Jonas Karlman, Jernej Skrabec,
	stable, Tomeu Vizoso

On Fri, Oct 1, 2021 at 1:37 PM Sean Paul <sean@poorly.run> wrote:
> On Wed, Sep 29, 2021 at 02:41:03PM -0700, Brian Norris wrote:
> > --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> > +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
> > @@ -1632,8 +1632,23 @@ static ssize_t analogix_dpaux_transfer(struct drm_dp_aux *aux,
> >                                      struct drm_dp_aux_msg *msg)
> >  {
> >       struct analogix_dp_device *dp = to_dp(aux);
> > +     int ret, ret2;
> >
> > -     return analogix_dp_transfer(dp, msg);
> > +     ret = analogix_dp_prepare_panel(dp, true, false);
> > +     if (ret) {
> > +             DRM_DEV_ERROR(dp->dev, "Failed to prepare panel (%d)\n", ret);
>
> s/DRM_DEV_ERROR/drm_err/

Sure. Now that I'm looking a second time, I see the header recommends this.

> > +             return ret;
> > +     }
> > +
> > +     pm_runtime_get_sync(dp->dev);
> > +     ret = analogix_dp_transfer(dp, msg);
> > +     pm_runtime_put(dp->dev);
> > +
> > +     ret2 = analogix_dp_prepare_panel(dp, false, false);
> > +     if (ret2)
> > +             DRM_DEV_ERROR(dp->dev, "Failed to unprepare panel (%d)\n", ret2);
>
> What's the reasoning for not propagating unprepare failures? I feel like that
> should be fair game.

I suppose the underlying reason is laziness, sorry. But a related
reason is the we probably should prefer propagating the
analogix_dp_transfer() error, if it's non-zero, rather than the
unprepare error. That's not too hard to do though, even if it's
slightly more awkward.

> > +
> > +     return ret;
> >  }
> >
> >  struct analogix_dp_device *

v2 coming.

Regards,
Brian

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

end of thread, other threads:[~2021-10-01 21:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 21:41 [PATCH] drm/brdige: analogix_dp: Grab runtime PM reference for DP-AUX Brian Norris
2021-10-01 20:37 ` Sean Paul
2021-10-01 21:23   ` Brian Norris

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