Work around a problem with ww_mutexes in the drm modeset lock.
authorjsg <jsg@openbsd.org>
Tue, 9 Jan 2018 13:48:36 +0000 (13:48 +0000)
committerjsg <jsg@openbsd.org>
Tue, 9 Jan 2018 13:48:36 +0000 (13:48 +0000)
Screen blanks often result in a NULL dereference in __ww_mutex_lock with
lock->acquired being non zero and lock->ctx NULL.  mpi@ also reported
it occuring when switching from Xorg to a virtual terminal.

ok mpi@

sys/dev/pci/drm/linux_ww_mutex.h

index 69d50d4..fb1b267 100644 (file)
@@ -163,7 +163,8 @@ __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx, bool slow, bo
                          *   the `younger` process gives up all it's
                          *   resources.
                         */
-                       if (slow || ctx == NULL || ctx->stamp < lock->ctx->stamp) {
+                       if (slow || ctx == NULL ||
+                           (lock->ctx != NULL && ctx->stamp < lock->ctx->stamp)) {
                                int s = msleep(lock, &lock->lock,
                                               intr ? PCATCH : 0,
                                               ctx ? ctx->ww_class->name : "ww_mutex_lock", 0);