#define I915_SW_FENCE_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
 #endif
 
-#define I915_SW_FENCE_FLAG_ALLOC BIT(3) /* after WQ_FLAG_* for safety */
-
 static DEFINE_SPINLOCK(i915_sw_fence_lock);
 
+#define WQ_FLAG_BITS \
+       BITS_PER_TYPE(typeof_member(struct wait_queue_entry, flags))
+
+/* after WQ_FLAG_* for safety */
+#define I915_SW_FENCE_FLAG_FENCE BIT(WQ_FLAG_BITS - 1)
+#define I915_SW_FENCE_FLAG_ALLOC BIT(WQ_FLAG_BITS - 2)
+
 enum {
        DEBUG_FENCE_IDLE = 0,
        DEBUG_FENCE_NOTIFY,
        spin_lock_irqsave_nested(&x->lock, flags, 1 + !!continuation);
        if (continuation) {
                list_for_each_entry_safe(pos, next, &x->head, entry) {
-                       if (pos->func == autoremove_wake_function)
-                               pos->func(pos, TASK_NORMAL, 0, continuation);
-                       else
+                       if (pos->flags & I915_SW_FENCE_FLAG_FENCE)
                                list_move_tail(&pos->entry, continuation);
+                       else
+                               pos->func(pos, TASK_NORMAL, 0, continuation);
                }
        } else {
                LIST_HEAD(extra);
                        list_for_each_entry_safe(pos, next, &x->head, entry) {
                                int wake_flags;
 
-                               wake_flags = fence->error;
-                               if (pos->func == autoremove_wake_function)
-                                       wake_flags = 0;
+                               wake_flags = 0;
+                               if (pos->flags & I915_SW_FENCE_FLAG_FENCE)
+                                       wake_flags = fence->error;
 
                                pos->func(pos, TASK_NORMAL, wake_flags, &extra);
                        }
                                          struct i915_sw_fence *signaler,
                                          wait_queue_entry_t *wq, gfp_t gfp)
 {
+       unsigned int pending;
        unsigned long flags;
-       int pending;
 
        debug_fence_assert(fence);
        might_sleep_if(gfpflags_allow_blocking(gfp));
        if (unlikely(i915_sw_fence_check_if_after(fence, signaler)))
                return -EINVAL;
 
-       pending = 0;
+       pending = I915_SW_FENCE_FLAG_FENCE;
        if (!wq) {
                wq = kmalloc(sizeof(*wq), gfp);
                if (!wq) {