diff options
| author | Pan Xinhui <xinhuix.pan@intel.com> | 2015-09-09 15:37:02 -0700 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-04-11 10:59:37 +0200 |
| commit | 8f8189364f23f4cf61302aa1e8d1bea33e3dfd7d (patch) | |
| tree | 4f851b1e0a5cea233c300f6936c2e7c3e2b50051 | |
| parent | aeecbe64ee89f4b70108e3287071f6c27ea5db09 (diff) | |
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>
| -rw-r--r-- | lib/bitmap.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c index c1da6dbd1..7b2bc1ed4 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -383,7 +383,8 @@ int __bitmap_parse(const char *buf, unsigned int buflen, nchunks = nbits = totaldigits = c = 0; do { - chunk = ndigits = 0; + chunk = 0; + ndigits = totaldigits; /* Get the next chunk of the bitmap */ while (buflen) { @@ -422,9 +423,9 @@ int __bitmap_parse(const char *buf, unsigned int buflen, return -EOVERFLOW; chunk = (chunk << 4) | hex_to_bin(c); - ndigits++; totaldigits++; + totaldigits++; } - if (ndigits == 0) + if (ndigits == totaldigits) return -EINVAL; if (nchunks == 0 && chunk == 0) continue; |
