From: Luca Ceresoli Date: Tue, 24 Mar 2026 08:58:08 +0000 (+0100) Subject: drm/encoder: add mutex to protect the bridge chain X-Git-Tag: v7.2-rc1~141^2~26^2~79 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=01b92f0d18214660d9978f0c4dd9507ee8d27d06;p=thirdparty%2Flinux.git drm/encoder: add mutex to protect the bridge chain The per-encoder bridge chain is currently assumed to be static once it is fully initialized. Work is in progress to add hot-pluggable bridges, breaking that assumption. With bridge removal, the encoder chain can change without notice, removing tail bridges. This can be problematic while iterating over the chain. Add a mutex to be taken whenever looping or changing the encoder chain. Reviewed-by: Maxime Ripard Reviewed-by: Louis Chauvet Link: https://patch.msgid.link/20260324-drm-bridge-alloc-encoder-chain-mutex-v5-1-8bf786c5c7e6@bootlin.com Signed-off-by: Luca Ceresoli --- diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c index 8f2bc6a284822..3261f142baea3 100644 --- a/drivers/gpu/drm/drm_encoder.c +++ b/drivers/gpu/drm/drm_encoder.c @@ -129,6 +129,7 @@ static int __drm_encoder_init(struct drm_device *dev, } INIT_LIST_HEAD(&encoder->bridge_chain); + mutex_init(&encoder->bridge_chain_mutex); list_add_tail(&encoder->head, &dev->mode_config.encoder_list); encoder->index = dev->mode_config.num_encoder++; @@ -202,6 +203,7 @@ void drm_encoder_cleanup(struct drm_encoder *encoder) kfree(encoder->name); list_del(&encoder->head); dev->mode_config.num_encoder--; + mutex_destroy(&encoder->bridge_chain_mutex); memset(encoder, 0, sizeof(*encoder)); } diff --git a/include/drm/drm_encoder.h b/include/drm/drm_encoder.h index 977a9381c8ba9..eded7c34481a2 100644 --- a/include/drm/drm_encoder.h +++ b/include/drm/drm_encoder.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -189,6 +190,9 @@ struct drm_encoder { */ struct list_head bridge_chain; + /** @bridge_chain_mutex: protect bridge_chain from changes while iterating */ + struct mutex bridge_chain_mutex; + const struct drm_encoder_funcs *funcs; const struct drm_encoder_helper_funcs *helper_private;