Skip to content

Commit

Permalink
lib: bitmap: simplify bitmap_parselist
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Villemoes authored and torvalds committed Aug 7, 2014
1 parent 154f5e3 commit bc5be18
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit bc5be18

Please sign in to comment.