drm_bridge_helper_reset_crtc() takes the connection mutex using the
acquire context provided by the caller, and then relies on
drm_atomic_get_connector_for_encoder() and
drm_atomic_helper_reset_crtc() that both use the same context.
However, drm_atomic_get_connector_for_encoder() takes the connection
mutex itself and unlocks it on its way out. The connection mutex taken
by drm_bridge_helper_reset_crtc() was thus already released when the
function unlocked it again on its exit path, and the connector state
was looked at without holding it.
The callers already have to release the context locks through
drm_modeset_drop_locks() and to handle the -EDEADLK error, so we can
leave the connection mutex release to them. Look the connector up with
drm_atomic_get_connector_for_encoder_locked() instead, so that the
connection mutex stays held from the lookup until the CRTC reset, and
make sure the connector is bound to a CRTC before resetting it.
Fixes: 56ae62124177 ("drm/bridge: Add helper to reset bridge pipeline")
Signed-off-by: Maxime Ripard <[email protected]>
---
drivers/gpu/drm/drm_bridge_helper.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/drm_bridge_helper.c
b/drivers/gpu/drm/drm_bridge_helper.c
index 0a3c8fee66b3..53c051cb2d65 100644
--- a/drivers/gpu/drm/drm_bridge_helper.c
+++ b/drivers/gpu/drm/drm_bridge_helper.c
@@ -17,10 +17,14 @@
* between the CRTC and connector that bridge is connected to.
*
* As it relies on drm_atomic_helper_reset_crtc(), the same limitations
* apply.
*
+ * All the locks taken by this function use @ctx: the caller is
+ * responsible for releasing them with drm_modeset_drop_locks(), and
+ * for handling an -EDEADLK error with drm_modeset_backoff().
+ *
* Returns:
*
* 0 on success or a negative error code on failure. If the error
* returned is EDEADLK, the whole atomic sequence must be restarted.
*/
@@ -31,28 +35,27 @@ int drm_bridge_helper_reset_crtc(struct drm_bridge *bridge,
struct drm_encoder *encoder = bridge->encoder;
struct drm_device *dev = encoder->dev;
struct drm_crtc *crtc;
int ret;
+ /*
+ * Hold the connection mutex across the connector lookup and
+ * the accesses to its state, so that a concurrent commit can't
+ * re-route the connector in between. Every lock taken with @ctx
+ * is released by the caller through drm_modeset_drop_locks(),
+ * so we must not unlock it ourselves.
+ */
ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx);
if (ret)
return ret;
- connector = drm_atomic_get_connector_for_encoder(encoder, ctx);
- if (IS_ERR(connector)) {
- ret = PTR_ERR(connector);
- goto out;
- }
-
- if (!connector->state) {
- ret = -EINVAL;
- goto out;
- }
+ connector = drm_atomic_get_connector_for_encoder_locked(encoder);
+ if (IS_ERR(connector))
+ return PTR_ERR(connector);
crtc = connector->state->crtc;
- ret = drm_atomic_helper_reset_crtc(crtc, ctx);
+ if (!crtc)
+ return -EINVAL;
-out:
- drm_modeset_unlock(&dev->mode_config.connection_mutex);
- return ret;
+ return drm_atomic_helper_reset_crtc(crtc, ctx);
}
EXPORT_SYMBOL(drm_bridge_helper_reset_crtc);
--
2.56.1