summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2022-11-07 15:45:23 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-11-08 11:05:44 +0100
commit2d11e1838be14b9f5ba409da0fd4b07a162cc03c (patch)
treea47996814a426581183173fcec1901f17e21991d
parent5c43e199cbfd08180a02706d284d6c5834e97594 (diff)
downloadbarebox-2d11e1838be14b9f5ba409da0fd4b07a162cc03c.tar.gz
barebox-2d11e1838be14b9f5ba409da0fd4b07a162cc03c.tar.xz
bitops: implement assign_bit()
assign_bit() is a useful shortcut to if (foo) set_bit(); else clear_bit(); Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20221107144524.489471-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/linux/bitops.h14
1 files changed, 14 insertions, 0 deletions
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