[PATCH 1/4] bitops: Introduce assign_bit()
From: Lukas Wunner <lukas@wunner.de>
Date: 2017-08-21 13:12:22
Subsystem:
bitops api, device-mapper (lvm), the rest · Maintainers:
Yury Norov, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Linus Torvalds
A common idiom is to assign a value to a bit with:
if (value)
set_bit(nr, addr);
else
clear_bit(nr, addr);
Likewise common is the one-line expression variant:
value ? set_bit(nr, addr) : clear_bit(nr, addr);
Commit 9a8ac3ae682e ("dm mpath: cleanup QUEUE_IF_NO_PATH bit
manipulation by introducing assign_bit()") introduced assign_bit()
to the md subsystem for brevity.
Make it available to others, in particular gpiolib and the upcoming
driver for Maxim MAX3191x industrial serializer chips.
Cc: Bart Van Assche <redacted>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: Mike Snitzer <redacted>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
drivers/md/dm-mpath.c | 8 --------
include/linux/bitops.h | 24 ++++++++++++++++++++++++
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 0e8ab5bb3575..c79c113b7e7d 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c@@ -638,14 +638,6 @@ static void process_queued_bios(struct work_struct *work) blk_finish_plug(&plug); } -static void assign_bit(bool value, long nr, unsigned long *addr) -{ - if (value) - set_bit(nr, addr); - else - clear_bit(nr, addr); -} - /* * If we run out of usable paths, should we queue I/O or error it? */
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a83c822c35c2..097af36887c0 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h@@ -226,6 +226,30 @@ static inline unsigned long __ffs64(u64 word) return __ffs((unsigned long)word); } +/** + * assign_bit - Assign value to a bit in memory + * @value: the value to assign + * @nr: the bit to set + * @addr: the address to start counting from + */ +static __always_inline void assign_bit(bool value, long nr, + volatile unsigned long *addr) +{ + if (value) + set_bit(nr, addr); + else + clear_bit(nr, addr); +} + +static __always_inline void __assign_bit(bool value, long nr, + volatile unsigned long *addr) +{ + if (value) + __set_bit(nr, addr); + else + __clear_bit(nr, addr); +} + #ifdef __KERNEL__ #ifndef set_mask_bits
--
2.11.0