aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorLukas Wunner <lukas@wunner.de>2017-10-12 06:40:10 -0400
committerLinus Walleij <linus.walleij@linaro.org>2017-10-19 16:32:38 -0400
commit5307e2ad69ab3b0e0622fdf8b254c1d4565eb924 (patch)
tree8e4283ec0a9ef7ac7eaf5a22c3ecbb10ab496dc4 /include/linux
parent07901a94f9f9b11cc3a4537e33229cb7e7df5d2a (diff)
bitops: Introduce assign_bit()
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, specifically gpiolib and the upcoming driver for Maxim MAX3191x industrial serializer chips. As requested by Peter Zijlstra, change the argument order to reflect traditional "dst = src" in C, hence "assign_bit(nr, addr, value)". Cc: Bart Van Assche <bart.vanassche@wdc.com> Cc: Alasdair Kergon <agk@redhat.com> Cc: Mike Snitzer <snitzer@redhat.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Neil Brown <neilb@suse.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Theodore Ts'o <tytso@mit.edu> Cc: Borislav Petkov <bp@alien8.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Acked-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/bitops.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 8fbe259b197c..9a874deee6e2 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -227,6 +227,30 @@ static inline unsigned long __ffs64(u64 word)
227 return __ffs((unsigned long)word); 227 return __ffs((unsigned long)word);
228} 228}
229 229
230/**
231 * assign_bit - Assign value to a bit in memory
232 * @nr: the bit to set
233 * @addr: the address to start counting from
234 * @value: the value to assign
235 */
236static __always_inline void assign_bit(long nr, volatile unsigned long *addr,
237 bool value)
238{
239 if (value)
240 set_bit(nr, addr);
241 else
242 clear_bit(nr, addr);
243}
244
245static __always_inline void __assign_bit(long nr, volatile unsigned long *addr,
246 bool value)
247{
248 if (value)
249 __set_bit(nr, addr);
250 else
251 __clear_bit(nr, addr);
252}
253
230#ifdef __KERNEL__ 254#ifdef __KERNEL__
231 255
232#ifndef set_mask_bits 256#ifndef set_mask_bits