提交 bc5be182 编写于 作者: R Rasmus Villemoes 提交者: Linus Torvalds

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: NRasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 154f5e38
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册