Skip to content

Commit ce4320d

Browse files
rpears0ntorvalds
authored andcommitted
crc32: fix mixing of endian-specific types
crc32.c in its original version freely mixed u32, __le32 and __be32 types which caused warnings from sparse with __CHECK_ENDIAN__. This patch fixes these by forcing the types to u32. [[email protected]: Minor changelog tweaks] Signed-off-by: Bob Pearson <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 60e58d5 commit ce4320d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/crc32.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
#include "crc32defs.h"
2929

3030
#if CRC_LE_BITS == 8
31-
# define tole(x) __constant_cpu_to_le32(x)
31+
# define tole(x) ((__force u32) __constant_cpu_to_le32(x))
3232
#else
3333
# define tole(x) (x)
3434
#endif
3535

3636
#if CRC_BE_BITS == 8
37-
# define tobe(x) __constant_cpu_to_be32(x)
37+
# define tobe(x) ((__force u32) __constant_cpu_to_be32(x))
3838
#else
3939
# define tobe(x) (x)
4040
#endif
@@ -128,9 +128,9 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)
128128
# elif CRC_LE_BITS == 8
129129
const u32 (*tab)[] = crc32table_le;
130130

131-
crc = __cpu_to_le32(crc);
131+
crc = (__force u32) __cpu_to_le32(crc);
132132
crc = crc32_body(crc, p, len, tab);
133-
crc = __le32_to_cpu(crc);
133+
crc = __le32_to_cpu((__force __le32)crc);
134134
#endif
135135
return crc;
136136
}
@@ -171,9 +171,9 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
171171
# elif CRC_BE_BITS == 8
172172
const u32 (*tab)[] = crc32table_be;
173173

174-
crc = __cpu_to_be32(crc);
174+
crc = (__force u32) __cpu_to_be32(crc);
175175
crc = crc32_body(crc, p, len, tab);
176-
crc = __be32_to_cpu(crc);
176+
crc = __be32_to_cpu((__force __be32)crc);
177177
# endif
178178
return crc;
179179
}

0 commit comments

Comments
 (0)