Skip to contentSkip to conversation

lib: crc32: crc32_generic_shift: fix comment on iteration count

PATCH New Nicolai Stange 1 participant 1 message Oct 21, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: crc32: crc32_generic_shift: fix comment on iteration count

In crc32_generic_shift(), the linear startup phase is commented with a statement saying that "up to 32 bits" will be shifted in a linear way.

However, the loop following that comment, namely

for (i = 0; i < 8 * (int)(len & 3); i++) {...}

shifts only up to 8*3=24 bits.

Given the fact, that the binary method for exponentiation sets in at 2^2*8=32, the loop's bounds are correct: it handles the cases that any of the two least significant bits are set in len, i.e. the cases 2^1*8 and 2^0*8 which sum to 24.

Fix the comment.

---
 lib/crc32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/crc32.c +1 -1
index 9a907d4..a1d17db 100644
@@ -242,7 +242,7 @@ static u32 __attribute_const__ crc32_generic_shift(u32 crc, size_t len,
 	u32 power = polynomial;	/* CRC of x^32 */
 	int i;
 
-	/* Shift up to 32 bits in the simple linear way */
+	/* Shift up to 24 bits in the simple linear way */
 	for (i = 0; i < 8 * (int)(len & 3); i++)
 		crc = (crc >> 1) ^ (crc & 1 ? polynomial : 0);
 
Signature · 1 line
2.6.1