All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3, RESEND] lib/bitmap.c: correct a code style and do some, optimization
@ 2015-07-01 10:50 Pan Xinhui
  2015-07-01 10:51 ` [PATCH 2/3, RESEND] lib/bitmap.c: fix a special string handling bug in __bitmap_parselist Pan Xinhui
  0 siblings, 1 reply; 3+ messages in thread
From: Pan Xinhui @ 2015-07-01 10:50 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org
  Cc: Yury Norov, Andrew Morton, Rasmus Villemoes, tj, peterz,
	sudeep.holla, mina86, mnipxh@163.com, Alexey Klimov,
	yanmin_zhang@linux.intel.com


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>
---
 lib/bitmap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index a578a01..eb21456 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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-01 10:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-01 10:50 [PATCH 1/3, RESEND] lib/bitmap.c: correct a code style and do some, optimization Pan Xinhui
2015-07-01 10:51 ` [PATCH 2/3, RESEND] lib/bitmap.c: fix a special string handling bug in __bitmap_parselist Pan Xinhui
2015-07-01 10:52   ` [PATCH 3/3, RESEND] lib/bitmap.c: bitmap_parselist can accept string with whitespaces on head or tail Pan Xinhui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.