[U-Boot] [PATCH] crc32: fix recent bug

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Wed Nov 4 12:33:26 CET 2009


patch "crc32: more optimizations" introduced a bug.
This fixes it.

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund at transmode.se>
---

 Perhaps I should resend as one whole patch with
 everything instead?

 lib_generic/crc32.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib_generic/crc32.c b/lib_generic/crc32.c
index 2837d93..7f5abb1 100644
--- a/lib_generic/crc32.c
+++ b/lib_generic/crc32.c
@@ -180,7 +180,7 @@ uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
 {
     const uint32_t *tab = crc_table;
     const uint32_t *b =(uint32_t *)buf;
-    size_t save_len;
+    size_t rem_len;
 #ifdef DYNAMIC_CRC_TABLE
     if (crc_table_empty)
       make_crc_table();
@@ -188,14 +188,14 @@ uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
     crc = __cpu_to_le32(crc);
     /* Align it */
     if(((long)b)&3 && len) {
-	 uint8_t *p = (uint8_t *)b - 1;
+	 uint8_t *p = (uint8_t *)b;
 	 do {
-	      DO_CRC(*++p); /* use pre increment for speed */
-	 } while ((--len) && ((long)b)&3 );
-	 b = (uint32_t *)p + 1;
+	      DO_CRC(*p++);
+	 } while ((--len) && ((long)p)&3);
+	 b = (uint32_t *)p;
     }
 
-    save_len = len & 3;
+    rem_len = len & 3;
     len = len >> 2;
     for (--b; len; --len) {
 	 /* load data 32 bits wide, xor data 32 bits wide. */
@@ -205,10 +205,10 @@ uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
 	 DO_CRC(0);
 	 DO_CRC(0);
     }
-    len = save_len;
+    len = rem_len;
     /* And the last few bytes */
     if (len) {
-	 uint8_t *p = (uint8_t *)(b++) - 1;
+	 uint8_t *p = (uint8_t *)(b + 1) - 1;
 	 do {
 	      DO_CRC(*++p); /* use pre increment for speed */
 	 } while (--len);
-- 
1.6.4.4



More information about the U-Boot mailing list