lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <55939DCB.5070100@intel.com>
Date:	Wed, 01 Jul 2015 15:59:07 +0800
From:	Pan Xinhui <xinhuix.pan@...el.com>
To:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:	Yury Norov <yury.norov@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Rasmus Villemoes <linux@...musvillemoes.dk>, tj@...nel.org,
	peterz@...radead.org, sudeep.holla@....com, mina86@...a86.com,
	"mnipxh@....com" <mnipxh@....com>,
	Alexey Klimov <klimov.linux@...il.com>,
	"yanmin_zhang@...ux.intel.com" <yanmin_zhang@...ux.intel.com>
Subject: [PATCH 1/3] lib/bitmap.c: correct a code style and do some optimization
 in __bitmap_parse


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@...el.com>
Cc: Yury Norov <yury.norov@...il.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ