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.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -186,7 +186,7 @@ bitmap_find_next_zero_area(unsigned long *map, · 185 unmodified lines | ||
| 186 | 186 | align_mask, 0); |
| 187 | 187 | } |
| 188 | 188 | |
| 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, | |
| 190 | 190 | unsigned long *dst, int nbits); |
| 191 | 191 | extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, |
| 192 | 192 | unsigned long *dst, int nbits); |
| @@ -454,12 +454,6 @@ static inline void bitmap_replace(unsigned long *dst, · 261 unmodified lines | ||
| 454 | 454 | __bitmap_replace(dst, old, new, mask, nbits); |
| 455 | 455 | } |
| 456 | 456 | |
| 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 | − | |
| 463 | 457 | static inline void bitmap_next_clear_region(unsigned long *bitmap, |
| 464 | 458 | unsigned int *rs, unsigned int *re, |
| 465 | 459 | unsigned int end) |