2022-07-07 22:28:59

by Paul Menzel

[permalink] [raw]
Subject: [PATCH] lib/bitmap: Make length parameter `len` unsigned

The length is non-negative, so make it unsigned, and adapt while
condition accordingly.

Signed-off-by: Paul Menzel <[email protected]>
---
lib/bitmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index b18e31ea6e66..0746beb336df 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -348,14 +348,14 @@ int __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
}
EXPORT_SYMBOL(__bitmap_weight);

-void __bitmap_set(unsigned long *map, unsigned int start, int len)
+void __bitmap_set(unsigned long *map, unsigned int start, unsigned int len)
{
unsigned long *p = map + BIT_WORD(start);
const unsigned int size = start + len;
int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);

- while (len - bits_to_set >= 0) {
+ while (len >= bits_to_set) {
*p |= mask_to_set;
len -= bits_to_set;
bits_to_set = BITS_PER_LONG;
--
2.36.1


2022-07-07 22:53:34

by Yury Norov

[permalink] [raw]
Subject: Re: [PATCH] lib/bitmap: Make length parameter `len` unsigned

On Thu, Jul 07, 2022 at 11:50:52PM +0200, Paul Menzel wrote:
> The length is non-negative, so make it unsigned, and adapt while
> condition accordingly.
>
> Signed-off-by: Paul Menzel <[email protected]>

Applied, thanks!

> ---
> lib/bitmap.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index b18e31ea6e66..0746beb336df 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -348,14 +348,14 @@ int __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
> }
> EXPORT_SYMBOL(__bitmap_weight);
>
> -void __bitmap_set(unsigned long *map, unsigned int start, int len)
> +void __bitmap_set(unsigned long *map, unsigned int start, unsigned int len)
> {
> unsigned long *p = map + BIT_WORD(start);
> const unsigned int size = start + len;
> int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
> unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
>
> - while (len - bits_to_set >= 0) {
> + while (len >= bits_to_set) {
> *p |= mask_to_set;
> len -= bits_to_set;
> bits_to_set = BITS_PER_LONG;
> --
> 2.36.1