lib: bitmap: simplify bitmap_parselist
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Wed, 6 Aug 2014 23:10:12 +0000 (16:10 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 7 Aug 2014 01:01:26 +0000 (18:01 -0700)
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>
lib/bitmap.c

index 5d2540396300171a5ad9fa5a91ef0b22ed445cf0..d4b3a6d4b2d742c2fa9d0216ec1799e0ab12bf55 100644 (file)
@@ -665,13 +665,8 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
 
 int bitmap_parselist(const char *bp, unsigned long *maskp, int nmaskbits)
 {
-       char *nl  = strchr(bp, '\n');
-       int len;
-
-       if (nl)
-               len = nl - bp;
-       else
-               len = strlen(bp);
+       char *nl  = strchrnul(bp, '\n');
+       int len = nl - bp;
 
        return __bitmap_parselist(bp, len, 0, maskp, nmaskbits);
 }