Skip to contentSkip to conversation

nvmem: layouts: Switch from crc32() to crc32_le()

PATCH In review Eric Biggers 2 participants 2 messages Jun 20, 2025 – Jun 27, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: layouts: Switch from crc32() to crc32_le()

u_boot_env_parse() calls crc32() from within a scope that has a uint32_t variable named crc32. This works only because crc32() is actually a macro that expands to crc32_le(). I'm planning to make it an inline function instead, which will make the usual C scoping rules apply to it. Therefore, update u_boot_env_parse() to be compatible with that. To do so, just call crc32_le() directly instead of using the crc32() alias. (An alternative would be to rename the local variable.)

---

I'm planning to apply this patch to crc-next, since my patch
https://lore.kernel.org/r/[email protected]/
depends on this.

 drivers/nvmem/layouts/u-boot-env.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/layouts/u-boot-env.c +1 -1
index 436426d4e8f91..274e8a456e8c1 100644
@@ -146,11 +146,11 @@ int u_boot_env_parse(struct device *dev, struct nvmem_device *nvmem,
 	crc32_addr = (__le32 *)(buf + crc32_offset);
 	crc32 = le32_to_cpu(*crc32_addr);
 	crc32_data_len = dev_size - crc32_data_offset;
 	data_len = dev_size - data_offset;
 
-	calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L;
+	calc = crc32_le(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L;
 	if (calc != crc32) {
 		dev_err(dev, "Invalid calculated CRC32: 0x%08x (expected: 0x%08x)\n", calc, crc32);
 		err = -EINVAL;
 		goto err_kfree;
 	}

base-commit: e04c78d86a9699d136910cfc0bdcf01087e3267e

Signature · 1 line
2.50.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Biggers

u_boot_env_parse() calls crc32() from within a scope that has a uint32_t variable named crc32. This works only because crc32() is actually a macro that expands to crc32_le(). I'm planning to make it an inline function instead, which will make the usual C scoping rules apply to it. Therefore, update u_boot_env_parse() to be compatible with that. To do so, just call crc32_le() directly instead of using the crc32() alias. (An alternative would be to rename the local variable.)

Quoted 6 lines

---

I'm planning to apply this patch to crc-next, since my patch
https://lore.kernel.org/r/[email protected]/
depends on this.

--srini

Quoted 23 lines
 drivers/nvmem/layouts/u-boot-env.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/layouts/u-boot-env.c +1 -1
index 436426d4e8f91..274e8a456e8c1 100644
@@ -146,11 +146,11 @@ int u_boot_env_parse(struct device *dev, struct nvmem_device *nvmem,
 	crc32_addr = (__le32 *)(buf + crc32_offset);
 	crc32 = le32_to_cpu(*crc32_addr);
 	crc32_data_len = dev_size - crc32_data_offset;
 	data_len = dev_size - data_offset;
 
-	calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L;
+	calc = crc32_le(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L;
 	if (calc != crc32) {
 		dev_err(dev, "Invalid calculated CRC32: 0x%08x (expected: 0x%08x)\n", calc, crc32);
 		err = -EINVAL;
 		goto err_kfree;
 	}

base-commit: e04c78d86a9699d136910cfc0bdcf01087e3267e