History

lib: rework bitmap_parse()

bitmap_parse() is ineffective and full of opaque variables and opencoded parts. It leads to hard understanding and usage of it. This rework includes: - remove bitmap_shift_left() call from the cycle. Now it makes the complexity of the algorithm as O(nbits^2). In the suggested approach the input string is parsed in reverse direction, so no shifts needed; - relax requirement on a single comma and no white spaces between chunks. It is considered useful in scripting, and it aligns with bitmap_parselist(); - split bitmap_parse() to small readable helpers; - make an explicit calculation of the end of input line at the beginning, so users of the bitmap_parse() won't bother doing this.

Yury Norov committed 6 years ago

Commit 2d626151 parent e66eda02 files · +84 −99Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/bitmap.h+1−7
@@ -186,7 +186,7 @@ bitmap_find_next_zero_area(unsigned long *map, · 185 unmodified lines
186186 align_mask, 0);
187187 }
188188
189−extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user,
189+extern int bitmap_parse(const char *buf, unsigned int buflen,
190190 unsigned long *dst, int nbits);
191191 extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,
192192 unsigned long *dst, int nbits);
@@ -454,12 +454,6 @@ static inline void bitmap_replace(unsigned long *dst, · 261 unmodified lines
454454 __bitmap_replace(dst, old, new, mask, nbits);
455455 }
456456
457−static inline int bitmap_parse(const char *buf, unsigned int buflen,
458− unsigned long *maskp, int nmaskbits)
459−{
460− return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);
461−}
462−
463457 static inline void bitmap_next_clear_region(unsigned long *bitmap,
464458 unsigned int *rs, unsigned int *re,
465459 unsigned int end)