diff options
| author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2014-08-06 19:10:12 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 21:01:26 -0400 |
| commit | bc5be1828065681300f3727ab55fac0d7ef37af3 (patch) | |
| tree | c279a498e6da81b3ce6f4fd422982d430fa20883 /lib | |
| parent | 154f5e38f30f262025c8c2e825376f6eb51e8bcb (diff) | |
lib: bitmap: simplify bitmap_parselist
We want len to be the index of the first '\n', or the length of the
string if there is no newline. This is a good example of the usefulness
of strchrnul(). Use that instead, thus eliminating a branch and a call
to strlen().
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bitmap.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c index 5d2540396300..d4b3a6d4b2d7 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
| @@ -665,13 +665,8 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, | |||
| 665 | 665 | ||
| 666 | int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) | 666 | int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits) |
| 667 | { | 667 | { |
| 668 | char *nl = strchr(bp, '\n'); | 668 | char *nl = strchrnul(bp, '\n'); |
| 669 | int len; | 669 | int len = nl - bp; |
| 670 | |||
| 671 | if (nl) | ||
| 672 | len = nl - bp; | ||
| 673 | else | ||
| 674 | len = strlen(bp); | ||
| 675 | 670 | ||
| 676 | return __bitmap_parselist(bp, len, 0, maskp, nmaskbits); | 671 | return __bitmap_parselist(bp, len, 0, maskp, nmaskbits); |
| 677 | } | 672 | } |
