* [PATCH 0/8] lib: bitmap: Another small series
@ 2014-12-12 0:01 Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 1/8] lib: bitmap: More signed->unsigned conversions Rasmus Villemoes
` (7 more replies)
0 siblings, 8 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
I found some patches in a long-forgotten branch - they still applied
cleanly, so I spiced them up with a few extra simplifications and
signed->unsigned conversions.
Rasmus Villemoes (8):
lib: bitmap: More signed->unsigned conversions
linux/nodemask.h: Update bitmap wrappers to take unsigned int
linux/cpumask.h: Update bitmap wrappers to take unsigned int
lib: bitmap: Update bitmap_onto to unsigned
lib: bitmap: Change parameters of bitmap_fold to unsigned
lib: bitmap: Simplify bitmap_pos_to_ord
lib: bitmap: Simplify bitmap_ord_to_pos
lib: bitmap: Minor changes of bitmap_remap
include/linux/bitmap.h | 22 ++++++-------
include/linux/cpumask.h | 22 ++++++-------
include/linux/nodemask.h | 26 +++++++--------
lib/bitmap.c | 85 +++++++++++++++++++++---------------------------
4 files changed, 72 insertions(+), 83 deletions(-)
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/8] lib: bitmap: More signed->unsigned conversions
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 2/8] linux/nodemask.h: Update bitmap wrappers to take unsigned int Rasmus Villemoes
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
For consistency with the other bitmap_* functions, also make the nbits
parameter of bitmap_zero, bitmap_fill and bitmap_copy unsigned.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/bitmap.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index e1c8d080c427..0106f02e5a93 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -156,33 +156,33 @@ extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
#define small_const_nbits(nbits) \
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
-static inline void bitmap_zero(unsigned long *dst, int nbits)
+static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
{
if (small_const_nbits(nbits))
*dst = 0UL;
else {
- int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+ unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
memset(dst, 0, len);
}
}
-static inline void bitmap_fill(unsigned long *dst, int nbits)
+static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)
{
- size_t nlongs = BITS_TO_LONGS(nbits);
+ unsigned int nlongs = BITS_TO_LONGS(nbits);
if (!small_const_nbits(nbits)) {
- int len = (nlongs - 1) * sizeof(unsigned long);
+ unsigned int len = (nlongs - 1) * sizeof(unsigned long);
memset(dst, 0xff, len);
}
dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
}
static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
- int nbits)
+ unsigned int nbits)
{
if (small_const_nbits(nbits))
*dst = *src;
else {
- int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+ unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
memcpy(dst, src, len);
}
}
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/8] linux/nodemask.h: Update bitmap wrappers to take unsigned int
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 1/8] lib: bitmap: More signed->unsigned conversions Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 3/8] linux/cpumask.h: " Rasmus Villemoes
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton, David Rientjes; +Cc: Rasmus Villemoes, linux-kernel
Since the various bitmap_* functions now take an unsigned int as nbits
parameter, it makes sense to also update the various wrappers.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/nodemask.h | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 83a6aeda899d..21cef483dc1b 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -120,13 +120,13 @@ static inline void __node_clear(int node, volatile nodemask_t *dstp)
}
#define nodes_setall(dst) __nodes_setall(&(dst), MAX_NUMNODES)
-static inline void __nodes_setall(nodemask_t *dstp, int nbits)
+static inline void __nodes_setall(nodemask_t *dstp, unsigned int nbits)
{
bitmap_fill(dstp->bits, nbits);
}
#define nodes_clear(dst) __nodes_clear(&(dst), MAX_NUMNODES)
-static inline void __nodes_clear(nodemask_t *dstp, int nbits)
+static inline void __nodes_clear(nodemask_t *dstp, unsigned int nbits)
{
bitmap_zero(dstp->bits, nbits);
}
@@ -144,7 +144,7 @@ static inline int __node_test_and_set(int node, nodemask_t *addr)
#define nodes_and(dst, src1, src2) \
__nodes_and(&(dst), &(src1), &(src2), MAX_NUMNODES)
static inline void __nodes_and(nodemask_t *dstp, const nodemask_t *src1p,
- const nodemask_t *src2p, int nbits)
+ const nodemask_t *src2p, unsigned int nbits)
{
bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
}
@@ -152,7 +152,7 @@ static inline void __nodes_and(nodemask_t *dstp, const nodemask_t *src1p,
#define nodes_or(dst, src1, src2) \
__nodes_or(&(dst), &(src1), &(src2), MAX_NUMNODES)
static inline void __nodes_or(nodemask_t *dstp, const nodemask_t *src1p,
- const nodemask_t *src2p, int nbits)
+ const nodemask_t *src2p, unsigned int nbits)
{
bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
}
@@ -160,7 +160,7 @@ static inline void __nodes_or(nodemask_t *dstp, const nodemask_t *src1p,
#define nodes_xor(dst, src1, src2) \
__nodes_xor(&(dst), &(src1), &(src2), MAX_NUMNODES)
static inline void __nodes_xor(nodemask_t *dstp, const nodemask_t *src1p,
- const nodemask_t *src2p, int nbits)
+ const nodemask_t *src2p, unsigned int nbits)
{
bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
}
@@ -168,7 +168,7 @@ static inline void __nodes_xor(nodemask_t *dstp, const nodemask_t *src1p,
#define nodes_andnot(dst, src1, src2) \
__nodes_andnot(&(dst), &(src1), &(src2), MAX_NUMNODES)
static inline void __nodes_andnot(nodemask_t *dstp, const nodemask_t *src1p,
- const nodemask_t *src2p, int nbits)
+ const nodemask_t *src2p, unsigned int nbits)
{
bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
}
@@ -176,7 +176,7 @@ static inline void __nodes_andnot(nodemask_t *dstp, const nodemask_t *src1p,
#define nodes_complement(dst, src) \
__nodes_complement(&(dst), &(src), MAX_NUMNODES)
static inline void __nodes_complement(nodemask_t *dstp,
- const nodemask_t *srcp, int nbits)
+ const nodemask_t *srcp, unsigned int nbits)
{
bitmap_complement(dstp->bits, srcp->bits, nbits);
}
@@ -184,7 +184,7 @@ static inline void __nodes_complement(nodemask_t *dstp,
#define nodes_equal(src1, src2) \
__nodes_equal(&(src1), &(src2), MAX_NUMNODES)
static inline int __nodes_equal(const nodemask_t *src1p,
- const nodemask_t *src2p, int nbits)
+ const nodemask_t *src2p, unsigned int nbits)
{
return bitmap_equal(src1p->bits, src2p->bits, nbits);
}
@@ -192,7 +192,7 @@ static inline int __nodes_equal(const nodemask_t *src1p,
#define nodes_intersects(src1, src2) \
__nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
static inline int __nodes_intersects(const nodemask_t *src1p,
- const nodemask_t *src2p, int nbits)
+ const nodemask_t *src2p, unsigned int nbits)
{
return bitmap_intersects(src1p->bits, src2p->bits, nbits);
}
@@ -200,25 +200,25 @@ static inline int __nodes_intersects(const nodemask_t *src1p,
#define nodes_subset(src1, src2) \
__nodes_subset(&(src1), &(src2), MAX_NUMNODES)
static inline int __nodes_subset(const nodemask_t *src1p,
- const nodemask_t *src2p, int nbits)
+ const nodemask_t *src2p, unsigned int nbits)
{
return bitmap_subset(src1p->bits, src2p->bits, nbits);
}
#define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
-static inline int __nodes_empty(const nodemask_t *srcp, int nbits)
+static inline int __nodes_empty(const nodemask_t *srcp, unsigned int nbits)
{
return bitmap_empty(srcp->bits, nbits);
}
#define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
-static inline int __nodes_full(const nodemask_t *srcp, int nbits)
+static inline int __nodes_full(const nodemask_t *srcp, unsigned int nbits)
{
return bitmap_full(srcp->bits, nbits);
}
#define nodes_weight(nodemask) __nodes_weight(&(nodemask), MAX_NUMNODES)
-static inline int __nodes_weight(const nodemask_t *srcp, int nbits)
+static inline int __nodes_weight(const nodemask_t *srcp, unsigned int nbits)
{
return bitmap_weight(srcp->bits, nbits);
}
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/8] linux/cpumask.h: Update bitmap wrappers to take unsigned int
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 1/8] lib: bitmap: More signed->unsigned conversions Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 2/8] linux/nodemask.h: Update bitmap wrappers to take unsigned int Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 4/8] lib: bitmap: Update bitmap_onto to unsigned Rasmus Villemoes
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton, David S. Miller; +Cc: Rasmus Villemoes, linux-kernel
Since the various bitmap_* functions now take an unsigned int as nbits
parameter, it makes sense to also update the various wrappers, even
though they're marked as obsolete.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/cpumask.h | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 0a9a6da21e74..7fd6f4018b5a 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -888,13 +888,13 @@ static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp)
}
#define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
-static inline void __cpus_setall(cpumask_t *dstp, int nbits)
+static inline void __cpus_setall(cpumask_t *dstp, unsigned int nbits)
{
bitmap_fill(dstp->bits, nbits);
}
#define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
-static inline void __cpus_clear(cpumask_t *dstp, int nbits)
+static inline void __cpus_clear(cpumask_t *dstp, unsigned int nbits)
{
bitmap_zero(dstp->bits, nbits);
}
@@ -910,21 +910,21 @@ static inline int __cpu_test_and_set(int cpu, cpumask_t *addr)
#define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS)
static inline int __cpus_and(cpumask_t *dstp, const cpumask_t *src1p,
- const cpumask_t *src2p, int nbits)
+ const cpumask_t *src2p, unsigned int nbits)
{
return bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
}
#define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS)
static inline void __cpus_or(cpumask_t *dstp, const cpumask_t *src1p,
- const cpumask_t *src2p, int nbits)
+ const cpumask_t *src2p, unsigned int nbits)
{
bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
}
#define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS)
static inline void __cpus_xor(cpumask_t *dstp, const cpumask_t *src1p,
- const cpumask_t *src2p, int nbits)
+ const cpumask_t *src2p, unsigned int nbits)
{
bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
}
@@ -932,40 +932,40 @@ static inline void __cpus_xor(cpumask_t *dstp, const cpumask_t *src1p,
#define cpus_andnot(dst, src1, src2) \
__cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS)
static inline int __cpus_andnot(cpumask_t *dstp, const cpumask_t *src1p,
- const cpumask_t *src2p, int nbits)
+ const cpumask_t *src2p, unsigned int nbits)
{
return bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
}
#define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)
static inline int __cpus_equal(const cpumask_t *src1p,
- const cpumask_t *src2p, int nbits)
+ const cpumask_t *src2p, unsigned int nbits)
{
return bitmap_equal(src1p->bits, src2p->bits, nbits);
}
#define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS)
static inline int __cpus_intersects(const cpumask_t *src1p,
- const cpumask_t *src2p, int nbits)
+ const cpumask_t *src2p, unsigned int nbits)
{
return bitmap_intersects(src1p->bits, src2p->bits, nbits);
}
#define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS)
static inline int __cpus_subset(const cpumask_t *src1p,
- const cpumask_t *src2p, int nbits)
+ const cpumask_t *src2p, unsigned int nbits)
{
return bitmap_subset(src1p->bits, src2p->bits, nbits);
}
#define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
-static inline int __cpus_empty(const cpumask_t *srcp, int nbits)
+static inline int __cpus_empty(const cpumask_t *srcp, unsigned int nbits)
{
return bitmap_empty(srcp->bits, nbits);
}
#define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
-static inline int __cpus_weight(const cpumask_t *srcp, int nbits)
+static inline int __cpus_weight(const cpumask_t *srcp, unsigned int nbits)
{
return bitmap_weight(srcp->bits, nbits);
}
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/8] lib: bitmap: Update bitmap_onto to unsigned
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
` (2 preceding siblings ...)
2014-12-12 0:01 ` [PATCH 3/8] linux/cpumask.h: " Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 5/8] lib: bitmap: Change parameters of bitmap_fold " Rasmus Villemoes
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
Change the nbits parameter of bitmap_onto to unsigned int for
consistency with other bitmap_* functions.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/bitmap.h | 2 +-
lib/bitmap.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 0106f02e5a93..bf29a08bb3db 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -137,7 +137,7 @@ extern void bitmap_remap(unsigned long *dst, const unsigned long *src,
extern int bitmap_bitremap(int oldbit,
const unsigned long *old, const unsigned long *new, int bits);
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
- const unsigned long *relmap, int bits);
+ const unsigned long *relmap, unsigned int bits);
extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
int sz, int bits);
extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
diff --git a/lib/bitmap.c b/lib/bitmap.c
index b499ab6ada29..42d5886c3680 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -975,9 +975,9 @@ EXPORT_SYMBOL(bitmap_bitremap);
* All bits in @dst not set by the above rule are cleared.
*/
void bitmap_onto(unsigned long *dst, const unsigned long *orig,
- const unsigned long *relmap, int bits)
+ const unsigned long *relmap, unsigned int bits)
{
- int n, m; /* same meaning as in above comment */
+ unsigned int n, m; /* same meaning as in above comment */
if (dst == orig) /* following doesn't handle inplace mappings */
return;
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 5/8] lib: bitmap: Change parameters of bitmap_fold to unsigned
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
` (3 preceding siblings ...)
2014-12-12 0:01 ` [PATCH 4/8] lib: bitmap: Update bitmap_onto to unsigned Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 6/8] lib: bitmap: Simplify bitmap_pos_to_ord Rasmus Villemoes
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
Change the sz and nbits parameters of bitmap_fold to unsigned int for
consistency with other bitmap_* functions, and to save another few
bytes in the generated code.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/bitmap.h | 2 +-
lib/bitmap.c | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index bf29a08bb3db..85e8fb091ed7 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -139,7 +139,7 @@ extern int bitmap_bitremap(int oldbit,
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
const unsigned long *relmap, unsigned int bits);
extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
- int sz, int bits);
+ unsigned int sz, unsigned int nbits);
extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 42d5886c3680..1807d089eda7 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -1015,15 +1015,15 @@ EXPORT_SYMBOL(bitmap_onto);
* Example [2] for bitmap_onto() for why and how to use this.
*/
void bitmap_fold(unsigned long *dst, const unsigned long *orig,
- int sz, int bits)
+ unsigned int sz, unsigned int nbits)
{
- int oldbit;
+ unsigned int oldbit;
if (dst == orig) /* following doesn't handle inplace mappings */
return;
- bitmap_zero(dst, bits);
+ bitmap_zero(dst, nbits);
- for_each_set_bit(oldbit, orig, bits)
+ for_each_set_bit(oldbit, orig, nbits)
set_bit(oldbit % sz, dst);
}
EXPORT_SYMBOL(bitmap_fold);
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 6/8] lib: bitmap: Simplify bitmap_pos_to_ord
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
` (4 preceding siblings ...)
2014-12-12 0:01 ` [PATCH 5/8] lib: bitmap: Change parameters of bitmap_fold " Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 7/8] lib: bitmap: Simplify bitmap_ord_to_pos Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 8/8] lib: bitmap: Minor changes of bitmap_remap Rasmus Villemoes
7 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
The ordinal of the a set bit is simply the number of set bits before
it; counting those doesn't need to be done one bit at a time. While at
it, update the parameters to unsigned int.
It is not completely unthinkable that gcc would see pos as
compile-time constant 0 in one of the uses of bitmap_pos_to_ord. Since
the static inline frontend bitmap_weight doesn't handle nbits==0
correctly (it would behave exactly as if nbits==BITS_PER_LONG), use
__bitmap_weight.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
Notes:
Alternatively, the last line could be spelled bitmap_weight(buf,
pos+1)-1, but this is simpler.
lib/bitmap.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 1807d089eda7..ab62a7e4d50f 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -713,10 +713,10 @@ EXPORT_SYMBOL(bitmap_parselist_user);
/**
* bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap
* @buf: pointer to a bitmap
- * @pos: a bit position in @buf (0 <= @pos < @bits)
- * @bits: number of valid bit positions in @buf
+ * @pos: a bit position in @buf (0 <= @pos < @nbits)
+ * @nbits: number of valid bit positions in @buf
*
- * Map the bit at position @pos in @buf (of length @bits) to the
+ * Map the bit at position @pos in @buf (of length @nbits) to the
* ordinal of which set bit it is. If it is not set or if @pos
* is not a valid bit position, map to -1.
*
@@ -728,22 +728,12 @@ EXPORT_SYMBOL(bitmap_parselist_user);
*
* The bit positions 0 through @bits are valid positions in @buf.
*/
-static int bitmap_pos_to_ord(const unsigned long *buf, int pos, int bits)
+static int bitmap_pos_to_ord(const unsigned long *buf, unsigned int pos, unsigned int nbits)
{
- int i, ord;
-
- if (pos < 0 || pos >= bits || !test_bit(pos, buf))
+ if (pos >= nbits || !test_bit(pos, buf))
return -1;
- i = find_first_bit(buf, bits);
- ord = 0;
- while (i < pos) {
- i = find_next_bit(buf, bits, i + 1);
- ord++;
- }
- BUG_ON(i != pos);
-
- return ord;
+ return __bitmap_weight(buf, pos);
}
/**
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 7/8] lib: bitmap: Simplify bitmap_ord_to_pos
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
` (5 preceding siblings ...)
2014-12-12 0:01 ` [PATCH 6/8] lib: bitmap: Simplify bitmap_pos_to_ord Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 8/8] lib: bitmap: Minor changes of bitmap_remap Rasmus Villemoes
7 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
Make the return value and the ord and nbits parameters of
bitmap_ord_to_pos unsigned.
Also, simplify the implementation and as a side effect make the result
fully defined, returning nbits for ord >= weight, in analogy with what
find_{first,next}_bit does. This is a better sentinel than the former
("unofficial") 0. No current users are affected by this change.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/bitmap.h | 2 +-
lib/bitmap.c | 28 +++++++++++-----------------
2 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 85e8fb091ed7..e854934cdbf9 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -144,7 +144,7 @@ extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int
extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
-extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
+extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits);
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
#define BITMAP_LAST_WORD_MASK(nbits) \
diff --git a/lib/bitmap.c b/lib/bitmap.c
index ab62a7e4d50f..89b61e42f173 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -740,34 +740,28 @@ static int bitmap_pos_to_ord(const unsigned long *buf, unsigned int pos, unsigne
* bitmap_ord_to_pos - find position of n-th set bit in bitmap
* @buf: pointer to bitmap
* @ord: ordinal bit position (n-th set bit, n >= 0)
- * @bits: number of valid bit positions in @buf
+ * @nbits: number of valid bit positions in @buf
*
* Map the ordinal offset of bit @ord in @buf to its position in @buf.
- * Value of @ord should be in range 0 <= @ord < weight(buf), else
- * results are undefined.
+ * Value of @ord should be in range 0 <= @ord < weight(buf). If @ord
+ * >= weight(buf), returns @nbits.
*
* If for example, just bits 4 through 7 are set in @buf, then @ord
* values 0 through 3 will get mapped to 4 through 7, respectively,
- * and all other @ord values return undefined values. When @ord value 3
+ * and all other @ord values returns @nbits. When @ord value 3
* gets mapped to (returns) @pos value 7 in this example, that means
* that the 3rd set bit (starting with 0th) is at position 7 in @buf.
*
- * The bit positions 0 through @bits are valid positions in @buf.
+ * The bit positions 0 through @nbits-1 are valid positions in @buf.
*/
-int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits)
+unsigned int bitmap_ord_to_pos(const unsigned long *buf, unsigned int ord, unsigned int nbits)
{
- int pos = 0;
+ unsigned int pos;
- if (ord >= 0 && ord < bits) {
- int i;
-
- for (i = find_first_bit(buf, bits);
- i < bits && ord > 0;
- i = find_next_bit(buf, bits, i + 1))
- ord--;
- if (i < bits && ord == 0)
- pos = i;
- }
+ for (pos = find_first_bit(buf, nbits);
+ pos < nbits && ord;
+ pos = find_next_bit(buf, nbits, pos + 1))
+ ord--;
return pos;
}
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 8/8] lib: bitmap: Minor changes of bitmap_remap
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
` (6 preceding siblings ...)
2014-12-12 0:01 ` [PATCH 7/8] lib: bitmap: Simplify bitmap_ord_to_pos Rasmus Villemoes
@ 2014-12-12 0:01 ` Rasmus Villemoes
2014-12-18 21:56 ` [PATCH 8/8 v2] lib: bitmap: Make the bits parameter of bitmap_remap unsigned Rasmus Villemoes
7 siblings, 1 reply; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-12 0:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
Make the nbits parameter unsigned for consistency with most other
bitmap_* functions, and pull the test of empty dst out of the loop.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/bitmap.h | 2 +-
lib/bitmap.c | 23 ++++++++++++++---------
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index e854934cdbf9..690b180d723a 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -133,7 +133,7 @@ extern int bitmap_parselist(const char *buf, unsigned long *maskp,
extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
unsigned long *dst, int nbits);
extern void bitmap_remap(unsigned long *dst, const unsigned long *src,
- const unsigned long *old, const unsigned long *new, int bits);
+ const unsigned long *old, const unsigned long *new, unsigned int nbits);
extern int bitmap_bitremap(int oldbit,
const unsigned long *old, const unsigned long *new, int bits);
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 89b61e42f173..eda3bf0673ad 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -772,7 +772,7 @@ unsigned int bitmap_ord_to_pos(const unsigned long *buf, unsigned int ord, unsig
* @src: subset to be remapped
* @old: defines domain of map
* @new: defines range of map
- * @bits: number of bits in each of these bitmaps
+ * @nbits: number of bits in each of these bitmaps
*
* Let @old and @new define a mapping of bit positions, such that
* whatever position is held by the n-th set bit in @old is mapped
@@ -800,22 +800,27 @@ unsigned int bitmap_ord_to_pos(const unsigned long *buf, unsigned int ord, unsig
*/
void bitmap_remap(unsigned long *dst, const unsigned long *src,
const unsigned long *old, const unsigned long *new,
- int bits)
+ unsigned int nbits)
{
- int oldbit, w;
+ unsigned int oldbit, w;
if (dst == src) /* following doesn't handle inplace remaps */
return;
- bitmap_zero(dst, bits);
- w = bitmap_weight(new, bits);
- for_each_set_bit(oldbit, src, bits) {
- int n = bitmap_pos_to_ord(old, oldbit, bits);
+ w = bitmap_weight(new, nbits);
+ if (!w) {
+ bitmap_copy(dst, src, nbits);
+ return;
+ }
+
+ bitmap_zero(dst, nbits);
+ for_each_set_bit(oldbit, src, nbits) {
+ int n = bitmap_pos_to_ord(old, oldbit, nbits);
- if (n < 0 || w == 0)
+ if (n < 0)
set_bit(oldbit, dst); /* identity map */
else
- set_bit(bitmap_ord_to_pos(new, n % w, bits), dst);
+ set_bit(bitmap_ord_to_pos(new, n % w, nbits), dst);
}
}
EXPORT_SYMBOL(bitmap_remap);
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 8/8 v2] lib: bitmap: Make the bits parameter of bitmap_remap unsigned
2014-12-12 0:01 ` [PATCH 8/8] lib: bitmap: Minor changes of bitmap_remap Rasmus Villemoes
@ 2014-12-18 21:56 ` Rasmus Villemoes
2014-12-19 9:23 ` [PATCH v3] " Rasmus Villemoes
0 siblings, 1 reply; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-18 21:56 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
... and rename it to nbits, both for consistency with other bitmap_*
functions.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
This is meant to replace 8/8 (lib: bitmap: Minor changes of
bitmap_remap), if you haven't gotten to that yet. No big deal either
way.
v2: Only do the signed->unsigned conversion. bitmap_remap only has a
single caller (via nodes_remap), so bloating it by special-casing
empty new isn't justified (and the commit log was wrong; it said
"empty dst").
include/linux/bitmap.h | 2 +-
lib/bitmap.c | 16 ++++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index e854934cdbf9..690b180d723a 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -133,7 +133,7 @@ extern int bitmap_parselist(const char *buf, unsigned long *maskp,
extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
unsigned long *dst, int nbits);
extern void bitmap_remap(unsigned long *dst, const unsigned long *src,
- const unsigned long *old, const unsigned long *new, int bits);
+ const unsigned long *old, const unsigned long *new, unsigned int nbits);
extern int bitmap_bitremap(int oldbit,
const unsigned long *old, const unsigned long *new, int bits);
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 89b61e42f173..e864ab008f85 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -772,7 +772,7 @@ unsigned int bitmap_ord_to_pos(const unsigned long *buf, unsigned int ord, unsig
* @src: subset to be remapped
* @old: defines domain of map
* @new: defines range of map
- * @bits: number of bits in each of these bitmaps
+ * @nbits: number of bits in each of these bitmaps
*
* Let @old and @new define a mapping of bit positions, such that
* whatever position is held by the n-th set bit in @old is mapped
@@ -800,22 +800,22 @@ unsigned int bitmap_ord_to_pos(const unsigned long *buf, unsigned int ord, unsig
*/
void bitmap_remap(unsigned long *dst, const unsigned long *src,
const unsigned long *old, const unsigned long *new,
- int bits)
+ unsigned int nbits)
{
- int oldbit, w;
+ unsigned int oldbit, w;
if (dst == src) /* following doesn't handle inplace remaps */
return;
- bitmap_zero(dst, bits);
+ bitmap_zero(dst, nbits);
- w = bitmap_weight(new, bits);
- for_each_set_bit(oldbit, src, bits) {
- int n = bitmap_pos_to_ord(old, oldbit, bits);
+ w = bitmap_weight(new, nbits);
+ for_each_set_bit(oldbit, src, nbits) {
+ int n = bitmap_pos_to_ord(old, oldbit, nbits);
if (n < 0 || w == 0)
set_bit(oldbit, dst); /* identity map */
else
- set_bit(bitmap_ord_to_pos(new, n % w, bits), dst);
+ set_bit(bitmap_ord_to_pos(new, n % w, nbits), dst);
}
}
EXPORT_SYMBOL(bitmap_remap);
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3] lib: bitmap: Make the bits parameter of bitmap_remap unsigned
2014-12-18 21:56 ` [PATCH 8/8 v2] lib: bitmap: Make the bits parameter of bitmap_remap unsigned Rasmus Villemoes
@ 2014-12-19 9:23 ` Rasmus Villemoes
0 siblings, 0 replies; 11+ messages in thread
From: Rasmus Villemoes @ 2014-12-19 9:23 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rasmus Villemoes, linux-kernel
Also, rename bits to nbits. Both changes for consistency with other
bitmap_* functions.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
Notes:
v3: Hopefully complete and unambiguous commit log.
v2: Only do the signed->unsigned conversion. bitmap_remap only has a
single caller (via nodes_remap), so bloating it by special-casing
empty new isn't justified (and the commit log was wrong; it said
"empty dst").
include/linux/bitmap.h | 2 +-
lib/bitmap.c | 16 ++++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index e1c8d080c427..1a634b0e0cbe 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -133,7 +133,7 @@ extern int bitmap_parselist(const char *buf, unsigned long *maskp,
extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
unsigned long *dst, int nbits);
extern void bitmap_remap(unsigned long *dst, const unsigned long *src,
- const unsigned long *old, const unsigned long *new, int bits);
+ const unsigned long *old, const unsigned long *new, unsigned int nbits);
extern int bitmap_bitremap(int oldbit,
const unsigned long *old, const unsigned long *new, int bits);
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
diff --git a/lib/bitmap.c b/lib/bitmap.c
index b499ab6ada29..5884b974407b 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -788,7 +788,7 @@ int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits)
* @src: subset to be remapped
* @old: defines domain of map
* @new: defines range of map
- * @bits: number of bits in each of these bitmaps
+ * @nbits: number of bits in each of these bitmaps
*
* Let @old and @new define a mapping of bit positions, such that
* whatever position is held by the n-th set bit in @old is mapped
@@ -816,22 +816,22 @@ int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits)
*/
void bitmap_remap(unsigned long *dst, const unsigned long *src,
const unsigned long *old, const unsigned long *new,
- int bits)
+ unsigned int nbits)
{
- int oldbit, w;
+ unsigned int oldbit, w;
if (dst == src) /* following doesn't handle inplace remaps */
return;
- bitmap_zero(dst, bits);
+ bitmap_zero(dst, nbits);
- w = bitmap_weight(new, bits);
- for_each_set_bit(oldbit, src, bits) {
- int n = bitmap_pos_to_ord(old, oldbit, bits);
+ w = bitmap_weight(new, nbits);
+ for_each_set_bit(oldbit, src, nbits) {
+ int n = bitmap_pos_to_ord(old, oldbit, nbits);
if (n < 0 || w == 0)
set_bit(oldbit, dst); /* identity map */
else
- set_bit(bitmap_ord_to_pos(new, n % w, bits), dst);
+ set_bit(bitmap_ord_to_pos(new, n % w, nbits), dst);
}
}
EXPORT_SYMBOL(bitmap_remap);
--
2.1.3
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-12-19 9:23 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-12 0:01 [PATCH 0/8] lib: bitmap: Another small series Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 1/8] lib: bitmap: More signed->unsigned conversions Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 2/8] linux/nodemask.h: Update bitmap wrappers to take unsigned int Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 3/8] linux/cpumask.h: " Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 4/8] lib: bitmap: Update bitmap_onto to unsigned Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 5/8] lib: bitmap: Change parameters of bitmap_fold " Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 6/8] lib: bitmap: Simplify bitmap_pos_to_ord Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 7/8] lib: bitmap: Simplify bitmap_ord_to_pos Rasmus Villemoes
2014-12-12 0:01 ` [PATCH 8/8] lib: bitmap: Minor changes of bitmap_remap Rasmus Villemoes
2014-12-18 21:56 ` [PATCH 8/8 v2] lib: bitmap: Make the bits parameter of bitmap_remap unsigned Rasmus Villemoes
2014-12-19 9:23 ` [PATCH v3] " Rasmus Villemoes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®