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>hifive-unleashed-5.1
parent
774636e19e
commit
d21c3d4d1c
|
@ -367,7 +367,8 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
|
||||||
|
|
||||||
nchunks = nbits = totaldigits = c = 0;
|
nchunks = nbits = totaldigits = c = 0;
|
||||||
do {
|
do {
|
||||||
chunk = ndigits = 0;
|
chunk = 0;
|
||||||
|
ndigits = totaldigits;
|
||||||
|
|
||||||
/* Get the next chunk of the bitmap */
|
/* Get the next chunk of the bitmap */
|
||||||
while (buflen) {
|
while (buflen) {
|
||||||
|
@ -406,9 +407,9 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
|
|
||||||
chunk = (chunk << 4) | hex_to_bin(c);
|
chunk = (chunk << 4) | hex_to_bin(c);
|
||||||
ndigits++; totaldigits++;
|
totaldigits++;
|
||||||
}
|
}
|
||||||
if (ndigits == 0)
|
if (ndigits == totaldigits)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (nchunks == 0 && chunk == 0)
|
if (nchunks == 0 && chunk == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue