diff options
Diffstat (limited to 'lib/crc32.c')
-rw-r--r-- | lib/crc32.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/crc32.c b/lib/crc32.c index 7394288c045c..5971f2ad46d5 100644 --- a/lib/crc32.c +++ b/lib/crc32.c | |||
@@ -27,13 +27,13 @@ | |||
27 | #include <linux/types.h> | 27 | #include <linux/types.h> |
28 | #include "crc32defs.h" | 28 | #include "crc32defs.h" |
29 | 29 | ||
30 | #if CRC_LE_BITS == 8 | 30 | #if CRC_LE_BITS > 8 |
31 | # define tole(x) ((__force u32) __constant_cpu_to_le32(x)) | 31 | # define tole(x) ((__force u32) __constant_cpu_to_le32(x)) |
32 | #else | 32 | #else |
33 | # define tole(x) (x) | 33 | # define tole(x) (x) |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #if CRC_BE_BITS == 8 | 36 | #if CRC_BE_BITS > 8 |
37 | # define tobe(x) ((__force u32) __constant_cpu_to_be32(x)) | 37 | # define tobe(x) ((__force u32) __constant_cpu_to_be32(x)) |
38 | #else | 38 | #else |
39 | # define tobe(x) (x) | 39 | # define tobe(x) (x) |
@@ -45,7 +45,7 @@ MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>"); | |||
45 | MODULE_DESCRIPTION("Ethernet CRC32 calculations"); | 45 | MODULE_DESCRIPTION("Ethernet CRC32 calculations"); |
46 | MODULE_LICENSE("GPL"); | 46 | MODULE_LICENSE("GPL"); |
47 | 47 | ||
48 | #if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 | 48 | #if CRC_LE_BITS > 8 || CRC_BE_BITS > 8 |
49 | 49 | ||
50 | static inline u32 | 50 | static inline u32 |
51 | crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256]) | 51 | 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) | |||
126 | crc = (crc >> 4) ^ crc32table_le[0][crc & 15]; | 126 | crc = (crc >> 4) ^ crc32table_le[0][crc & 15]; |
127 | } | 127 | } |
128 | # elif CRC_LE_BITS == 8 | 128 | # elif CRC_LE_BITS == 8 |
129 | /* aka Sarwate algorithm */ | ||
130 | while (len--) { | ||
131 | crc ^= *p++; | ||
132 | crc = (crc >> 8) ^ crc32table_le[0][crc & 255]; | ||
133 | } | ||
134 | # else | ||
129 | const u32 (*tab)[] = crc32table_le; | 135 | const u32 (*tab)[] = crc32table_le; |
130 | 136 | ||
131 | crc = (__force u32) __cpu_to_le32(crc); | 137 | crc = (__force u32) __cpu_to_le32(crc); |
@@ -169,6 +175,11 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | |||
169 | crc = (crc << 4) ^ crc32table_be[0][crc >> 28]; | 175 | crc = (crc << 4) ^ crc32table_be[0][crc >> 28]; |
170 | } | 176 | } |
171 | # elif CRC_BE_BITS == 8 | 177 | # elif CRC_BE_BITS == 8 |
178 | while (len--) { | ||
179 | crc ^= *p++ << 24; | ||
180 | crc = (crc << 8) ^ crc32table_be[0][crc >> 24]; | ||
181 | } | ||
182 | # else | ||
172 | const u32 (*tab)[] = crc32table_be; | 183 | const u32 (*tab)[] = crc32table_be; |
173 | 184 | ||
174 | crc = (__force u32) __cpu_to_be32(crc); | 185 | crc = (__force u32) __cpu_to_be32(crc); |