]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - lib/crc32.c
crc32: make CRC_*_BITS definition correspond to actual bit counts
[mirror_ubuntu-artful-kernel.git] / lib / crc32.c
index 7394288c045c8c32c68c2d77a27589aa54a89d15..5971f2ad46d5623203b2652e838b5de47a9be2d4 100644 (file)
 #include <linux/types.h>
 #include "crc32defs.h"
 
-#if CRC_LE_BITS == 8
+#if CRC_LE_BITS > 8
 # define tole(x) ((__force u32) __constant_cpu_to_le32(x))
 #else
 # define tole(x) (x)
 #endif
 
-#if CRC_BE_BITS == 8
+#if CRC_BE_BITS > 8
 # define tobe(x) ((__force u32) __constant_cpu_to_be32(x))
 #else
 # define tobe(x) (x)
@@ -45,7 +45,7 @@ MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>");
 MODULE_DESCRIPTION("Ethernet CRC32 calculations");
 MODULE_LICENSE("GPL");
 
-#if CRC_LE_BITS == 8 || CRC_BE_BITS == 8
+#if CRC_LE_BITS > 8 || CRC_BE_BITS > 8
 
 static inline u32
 crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
@@ -126,6 +126,12 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
                crc = (crc >> 4) ^ crc32table_le[0][crc & 15];
        }
 # elif CRC_LE_BITS == 8
+       /* aka Sarwate algorithm */
+       while (len--) {
+               crc ^= *p++;
+               crc = (crc >> 8) ^ crc32table_le[0][crc & 255];
+       }
+# else
        const u32      (*tab)[] = crc32table_le;
 
        crc = (__force u32) __cpu_to_le32(crc);
@@ -169,6 +175,11 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
                crc = (crc << 4) ^ crc32table_be[0][crc >> 28];
        }
 # elif CRC_BE_BITS == 8
+       while (len--) {
+               crc ^= *p++ << 24;
+               crc = (crc << 8) ^ crc32table_be[0][crc >> 24];
+       }
+# else
        const u32      (*tab)[] = crc32table_be;
 
        crc = (__force u32) __cpu_to_be32(crc);