From: Rasmus Villemoes Date: Wed, 6 Aug 2014 23:10:12 +0000 (-0700) Subject: lib: bitmap: simplify bitmap_parselist X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=bc5be1828065681300f3727ab55fac0d7ef37af3;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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 Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- 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); }