Skip to content

Commit d21c3d4

Browse files
Pan Xinhuitorvalds
authored andcommitted
lib/bitmap.c: correct a code style and do some, optimization
We can avoid in-loop incrementation of ndigits. Save current totaldigits to ndigits before loop, and check ndigits against totaldigits after the loop. Signed-off-by: Pan Xinhui <xinhuix.pan@intel.com> Cc: Yury Norov <yury.norov@gmail.com> Cc: Chris Metcalf <cmetcalf@ezchip.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 774636e commit d21c3d4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/bitmap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
367367

368368
nchunks = nbits = totaldigits = c = 0;
369369
do {
370-
chunk = ndigits = 0;
370+
chunk = 0;
371+
ndigits = totaldigits;
371372

372373
/* Get the next chunk of the bitmap */
373374
while (buflen) {
@@ -406,9 +407,9 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
406407
return -EOVERFLOW;
407408

408409
chunk = (chunk << 4) | hex_to_bin(c);
409-
ndigits++; totaldigits++;
410+
totaldigits++;
410411
}
411-
if (ndigits == 0)
412+
if (ndigits == totaldigits)
412413
return -EINVAL;
413414
if (nchunks == 0 && chunk == 0)
414415
continue;

0 commit comments

Comments
 (0)