Merge tag 'imx-drm-fixes-2016-05-24' of git://git.pengutronix.de/git/pza/linux into...
[cascardo/linux.git] / include / linux / bitops.h
index defeaac..299e76b 100644 (file)
@@ -227,6 +227,22 @@ static inline unsigned long __ffs64(u64 word)
 })
 #endif
 
+#ifndef bit_clear_unless
+#define bit_clear_unless(ptr, _clear, _test)   \
+({                                                             \
+       const typeof(*ptr) clear = (_clear), test = (_test);    \
+       typeof(*ptr) old, new;                                  \
+                                                               \
+       do {                                                    \
+               old = ACCESS_ONCE(*ptr);                        \
+               new = old & ~clear;                             \
+       } while (!(old & test) &&                               \
+                cmpxchg(ptr, old, new) != old);                \
+                                                               \
+       !(old & test);                                          \
+})
+#endif
+
 #ifndef find_last_bit
 /**
  * find_last_bit - find the last set bit in a memory region