[PATCH v2 1/2] drm/modeset_lock: add NULL check for ctx before WARN_ON

From: george . d . sworo

Date: Wed Apr 29 2026 - 02:04:55 EST


From: George D Sworo <george.d.sworo@xxxxxxxxx>

modeset_lock() and drm_modeset_drop_locks() do not validate
the ctx pointer before dereferencing it in WARN_ON(ctx->contended),
which can lead to a NULL pointer dereference if ctx is NULL.

Add a NULL check to prevent this.

Signed-off-by: George D Sworo <george.d.sworo@xxxxxxxxx>
---
drivers/gpu/drm/drm_modeset_lock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modeset_lock.c
index beb91a13a312..2052bb9bb9e5 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -295,7 +295,7 @@ static inline int modeset_lock(struct drm_modeset_lock *lock,
{
int ret;

- if (WARN_ON(ctx->contended))
+ if (ctx && WARN_ON(ctx->contended))
__drm_stack_depot_print(ctx->stack_depot);

if (ctx->trylock_only) {
--
2.34.1