[PATCH 02/16] lib/bitmap: don't call bitmap_set() with len == 0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



bitmap_parselist() format allows passing 0-length regions, but because
len == 0 is not covered by small_const_nbits() macro, we have to call
__bitmap_set() and do some prologue calculations just for nothing.

Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
 lib/bitmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index cd4dd848ea6a..790df2ea02df 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -712,10 +712,13 @@ struct region {
 
 static void bitmap_set_region(const struct region *r, unsigned long *bitmap)
 {
-	unsigned int start;
+	unsigned int start, len;
 
-	for (start = r->start; start <= r->end; start += r->group_len)
-		bitmap_set(bitmap, start, min(r->end - start + 1, r->off));
+	for (start = r->start; start <= r->end; start += r->group_len) {
+		len = min(r->end - start + 1, r->off);
+		if (len > 0)
+			bitmap_set(bitmap, start, len);
+	}
 }
 
 static int bitmap_check_region(const struct region *r)
-- 
2.34.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux