diff options
| author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2014-08-06 16:10:12 -0700 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-04-11 10:59:31 +0200 |
| commit | c8caa43ff99fecd0218da3c7181e99fdb9debb6d (patch) | |
| tree | 06f43bd15f78deef94796092a66824971f4b1917 | |
| parent | 5e54cec5f33efceaf540c94c7b17170cdd0c24e7 (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>
| -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 699a423fa..82b5b57fa 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -615,13 +615,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); } |
