diff options
author | Eric Biggers <ebiggers@google.com> | 2025-05-11 21:28:36 +0300 |
---|---|---|
committer | Thomas Bogendoerfer <tsbogend@alpha.franken.de> | 2025-05-20 09:44:33 +0300 |
commit | 2695b3c7fe4fa06a377ea0d66e3fe5fdb60310f0 (patch) | |
tree | 13951ced1a3c2d522fb9c5628444647961757c72 | |
parent | 3590692a136d75e39cd67b0f23e032669fcdbcd2 (diff) | |
download | linux-2695b3c7fe4fa06a377ea0d66e3fe5fdb60310f0.tar.xz |
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 <ebiggers@google.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
-rw-r--r-- | include/linux/bcm963xx_nvram.h | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/include/linux/bcm963xx_nvram.h b/include/linux/bcm963xx_nvram.h index c8c7f01159fe..48830bf18042 100644 --- a/include/linux/bcm963xx_nvram.h +++ b/include/linux/bcm963xx_nvram.h @@ -81,25 +81,21 @@ static int __maybe_unused bcm963xx_nvram_checksum( const struct bcm963xx_nvram *nvram, u32 *expected_out, u32 *actual_out) { + const u32 zero = 0; u32 expected, actual; size_t len; if (nvram->version <= 4) { expected = nvram->checksum_v4; - len = BCM963XX_NVRAM_V4_SIZE - sizeof(u32); + len = BCM963XX_NVRAM_V4_SIZE; } else { expected = nvram->checksum_v5; - len = BCM963XX_NVRAM_V5_SIZE - sizeof(u32); + len = BCM963XX_NVRAM_V5_SIZE; } - /* - * Calculate the CRC32 value for the nvram with a checksum value - * of 0 without modifying or copying the nvram by combining: - * - The CRC32 of the nvram without the checksum value - * - The CRC32 of a zero checksum value (which is also 0) - */ - actual = crc32_le_combine( - crc32_le(~0, (u8 *)nvram, len), 0, sizeof(u32)); + /* Calculate the CRC32 of the nvram with the checksum field set to 0. */ + actual = crc32_le(~0, nvram, len - sizeof(u32)); + actual = crc32_le(actual, &zero, sizeof(u32)); if (expected_out) *expected_out = expected; |