summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2014-07-17 10:58:18 +1000
committerStephen Rothwell <sfr@canb.auug.org.au>2014-07-17 10:58:18 +1000
commit588a62fb1a049f70f5e38b6dd969b9c7ef5bf5f4 (patch)
tree9b34b20a67928337c847588c443cb9e71fe6e5ca /lib
parent76aa8bed6695caef58c3dcf900ee857018d0ff26 (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>
Diffstat (limited to 'lib')
-rw-r--r--lib/bitmap.c9
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,
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);
}