[PATCH 3/4] bitops: implement assign_bit()

Sascha Hauer s.hauer at pengutronix.de
Mon Nov 7 06:45:23 PST 2022


assign_bit() is a useful shortcut to if (foo) set_bit(); else clear_bit();

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/linux/bitops.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 84161e43a3..eb5ff37f2f 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -194,6 +194,20 @@ static inline unsigned long __ffs64(u64 word)
 	return __ffs((unsigned long)word);
 }
 
+/**
+ * assign_bit - Assign value to a bit in memory
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ * @value: the value to assign
+ */
+static inline void assign_bit(long nr, volatile unsigned long *addr, bool value)
+{
+	if (value)
+		set_bit(nr, addr);
+	else
+		clear_bit(nr, addr);
+}
+
 #ifdef __KERNEL__
 
 #ifndef set_mask_bits
-- 
2.30.2




More information about the barebox mailing list