diff options
| author | Pan Xinhui <[email protected]> | 2015-09-09 22:37:02 +0000 |
|---|---|---|
| committer | Linus Torvalds <[email protected]> | 2015-09-10 20:29:01 +0000 |
| commit | d21c3d4d1c6b2a0b85aeae5cc774b1bacc64e5b4 (patch) | |
| tree | a31217219c5bfa59b21ad811984a9482da937e1b /lib/bitmap.c | |
| parent | proc: convert to kstrto*()/kstrto*_from_user() (diff) | |
| download | kernel-d21c3d4d1c6b2a0b85aeae5cc774b1bacc64e5b4.tar.gz kernel-d21c3d4d1c6b2a0b85aeae5cc774b1bacc64e5b4.zip | |
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 <[email protected]>
Cc: Yury Norov <[email protected]>
Cc: Chris Metcalf <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Sudeep Holla <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Diffstat (limited to 'lib/bitmap.c')
| -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 a578a0189199..eb21456be4b9 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -367,7 +367,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) { @@ -406,9 +407,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; |
