Skip to content

Commit 2695b3c

Browse files
ebiggerstsbogend
authored andcommitted
MIPS: bcm63xx: nvram: avoid inefficient use of crc32_le_combine()
bcm963xx_nvram_checksum() was using crc32_le_combine() to update a CRC with four zero bytes. However, this is about 5x slower than just CRC'ing four zero bytes in the normal way. Just do that instead. (We could instead make crc32_le_combine() faster on short lengths. But all its callers do just fine without it, so I'd like to just remove it.) Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent 3590692 commit 2695b3c

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

include/linux/bcm963xx_nvram.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,21 @@ static int __maybe_unused bcm963xx_nvram_checksum(
8181
const struct bcm963xx_nvram *nvram,
8282
u32 *expected_out, u32 *actual_out)
8383
{
84+
const u32 zero = 0;
8485
u32 expected, actual;
8586
size_t len;
8687

8788
if (nvram->version <= 4) {
8889
expected = nvram->checksum_v4;
89-
len = BCM963XX_NVRAM_V4_SIZE - sizeof(u32);
90+
len = BCM963XX_NVRAM_V4_SIZE;
9091
} else {
9192
expected = nvram->checksum_v5;
92-
len = BCM963XX_NVRAM_V5_SIZE - sizeof(u32);
93+
len = BCM963XX_NVRAM_V5_SIZE;
9394
}
9495

95-
/*
96-
* Calculate the CRC32 value for the nvram with a checksum value
97-
* of 0 without modifying or copying the nvram by combining:
98-
* - The CRC32 of the nvram without the checksum value
99-
* - The CRC32 of a zero checksum value (which is also 0)
100-
*/
101-
actual = crc32_le_combine(
102-
crc32_le(~0, (u8 *)nvram, len), 0, sizeof(u32));
96+
/* Calculate the CRC32 of the nvram with the checksum field set to 0. */
97+
actual = crc32_le(~0, nvram, len - sizeof(u32));
98+
actual = crc32_le(actual, &zero, sizeof(u32));
10399

104100
if (expected_out)
105101
*expected_out = expected;

0 commit comments

Comments
 (0)