summaryrefslogtreecommitdiffstats
path: root/sys/dev/pci/drm/include/linux/mutex.h
diff options
context:
space:
mode:
authorjsg <jsg@openbsd.org>2020-06-21 16:41:56 +0000
committerjsg <jsg@openbsd.org>2020-06-21 16:41:56 +0000
commitedef9da4822c7e22f40a459b5c59fe7c165437f9 (patch)
tree9f5defcd36c8f27a1c284eb0dee0359e772b163d /sys/dev/pci/drm/include/linux/mutex.h
parentSet up exec_map and phys_map. (diff)
downloadwireguard-openbsd-edef9da4822c7e22f40a459b5c59fe7c165437f9.tar.xz
wireguard-openbsd-edef9da4822c7e22f40a459b5c59fe7c165437f9.zip
correct mutex_lock_interruptible()
Linux kernel code often passes errors around as negative numbers cast to pointers. As rw_enter() returns a errno on failure mutex_lock_interruptible() negated the return value. But this did not account for ERESTART being -1 which would return 1 to the caller. sthen@ periodically hit a uvm_fault() in i915_request_create() which was caused by attempting to use 1 as a pointer. ok kettenis@
Diffstat (limited to 'sys/dev/pci/drm/include/linux/mutex.h')
-rw-r--r--sys/dev/pci/drm/include/linux/mutex.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/sys/dev/pci/drm/include/linux/mutex.h b/sys/dev/pci/drm/include/linux/mutex.h
index 5910b9743c0..f396289c62b 100644
--- a/sys/dev/pci/drm/include/linux/mutex.h
+++ b/sys/dev/pci/drm/include/linux/mutex.h
@@ -10,9 +10,8 @@
#define DEFINE_MUTEX(x) struct rwlock x
-#define mutex_lock_interruptible(rwl) -rw_enter(rwl, RW_WRITE | RW_INTR)
#define mutex_lock_interruptible_nested(rwl, subc) \
- -rw_enter(rwl, RW_WRITE | RW_INTR)
+ mutex_lock_interruptible(rwl)
#define mutex_lock(rwl) rw_enter_write(rwl)
#define mutex_lock_nest_lock(rwl, sub) rw_enter_write(rwl)
#define mutex_lock_nested(rwl, sub) rw_enter_write(rwl)
@@ -21,6 +20,14 @@
#define mutex_is_locked(rwl) (rw_status(rwl) != 0)
#define mutex_destroy(rwl)
+static inline int
+mutex_lock_interruptible(struct rwlock *rwl)
+{
+ if (rw_enter(rwl, RW_WRITE | RW_INTR) != 0)
+ return -EINTR;
+ return 0;
+}
+
enum mutex_trylock_recursive_result {
MUTEX_TRYLOCK_FAILED,
MUTEX_TRYLOCK_SUCCESS,