lkml.org 
[lkml]   [2013]   [Oct]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RFC 1/2] bitops: introduce BITS_MASK macro
Date
From: Srinivas Kandagatla <srinivas.kandagatla@st.com>

This patch introduces BITS_MASK macro which creates a mask for a given
lsb and msb bit locations. The usage of masks spread over mutiple bits
is becoming very common for example with regmap_update_bits kind of
apis. Having a common macro for this makes much sense and is clean and
readable way to encode the mask rather than having an hex number for a
mask.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
---
include/linux/bitops.h | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a3b6b82..3ddce97 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -5,6 +5,7 @@
#ifdef __KERNEL__
#define BIT(nr) (1UL << (nr))
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
+#define BITS_MASK(lsb, msb) ((BIT(msb - lsb + 1) - 1) << lsb)
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define BITS_PER_BYTE 8
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
--
1.7.6.5


\
 
 \ /
  Last update: 2013-10-31 13:21    [W:0.061 / U:0.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site