Skip to content

Commit ca459e5

Browse files
Avenger-285714herbertx
authored andcommitted
crypto: mips/crc32 - Clean up useless assignment operations
When entering the "len & sizeof(u32)" branch, len must be less than 8. So after one operation, len must be less than 4. At this time, "len -= sizeof(u32)" is not necessary for 64-bit CPUs. After that, replace `while' loops with equivalent `for' to make the code structure a little bit better by the way. Suggested-by: Maciej W. Rozycki <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Suggested-by: Herbert Xu <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Guan Wentao <[email protected]> Signed-off-by: WangYuli <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f29ca8f commit ca459e5

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

arch/mips/crypto/crc32-mips.c

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,26 @@ static u32 crc32_mips_le_hw(u32 crc_, const u8 *p, unsigned int len)
7777
{
7878
u32 crc = crc_;
7979

80-
#ifdef CONFIG_64BIT
81-
while (len >= sizeof(u64)) {
82-
u64 value = get_unaligned_le64(p);
83-
84-
CRC32(crc, value, d);
85-
p += sizeof(u64);
86-
len -= sizeof(u64);
87-
}
88-
89-
if (len & sizeof(u32)) {
90-
#else /* !CONFIG_64BIT */
91-
while (len >= sizeof(u32)) {
92-
#endif
93-
u32 value = get_unaligned_le32(p);
94-
95-
CRC32(crc, value, w);
96-
p += sizeof(u32);
97-
len -= sizeof(u32);
80+
if (IS_ENABLED(CONFIG_64BIT)) {
81+
for (; len >= sizeof(u64); p += sizeof(u64), len -= sizeof(u64)) {
82+
u64 value = get_unaligned_le64(p);
83+
84+
CRC32(crc, value, d);
85+
}
86+
87+
if (len & sizeof(u32)) {
88+
u32 value = get_unaligned_le32(p);
89+
90+
CRC32(crc, value, w);
91+
p += sizeof(u32);
92+
}
93+
} else {
94+
for (; len >= sizeof(u32); len -= sizeof(u32)) {
95+
u32 value = get_unaligned_le32(p);
96+
97+
CRC32(crc, value, w);
98+
p += sizeof(u32);
99+
}
98100
}
99101

100102
if (len & sizeof(u16)) {
@@ -117,24 +119,26 @@ static u32 crc32c_mips_le_hw(u32 crc_, const u8 *p, unsigned int len)
117119
{
118120
u32 crc = crc_;
119121

120-
#ifdef CONFIG_64BIT
121-
while (len >= sizeof(u64)) {
122-
u64 value = get_unaligned_le64(p);
122+
if (IS_ENABLED(CONFIG_64BIT)) {
123+
for (; len >= sizeof(u64); p += sizeof(u64), len -= sizeof(u64)) {
124+
u64 value = get_unaligned_le64(p);
123125

124-
CRC32C(crc, value, d);
125-
p += sizeof(u64);
126-
len -= sizeof(u64);
127-
}
126+
CRC32(crc, value, d);
127+
}
128128

129-
if (len & sizeof(u32)) {
130-
#else /* !CONFIG_64BIT */
131-
while (len >= sizeof(u32)) {
132-
#endif
133-
u32 value = get_unaligned_le32(p);
129+
if (len & sizeof(u32)) {
130+
u32 value = get_unaligned_le32(p);
131+
132+
CRC32(crc, value, w);
133+
p += sizeof(u32);
134+
}
135+
} else {
136+
for (; len >= sizeof(u32); len -= sizeof(u32)) {
137+
u32 value = get_unaligned_le32(p);
134138

135-
CRC32C(crc, value, w);
136-
p += sizeof(u32);
137-
len -= sizeof(u32);
139+
CRC32(crc, value, w);
140+
p += sizeof(u32);
141+
}
138142
}
139143

140144
if (len & sizeof(u16)) {

0 commit comments

Comments
 (0)