linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmem: layouts: Switch from crc32() to crc32_le()
@ 2025-06-20 20:50 Eric Biggers
  2025-06-27 10:57 ` Srinivas Kandagatla
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2025-06-20 20:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-crypto, Ard Biesheuvel, Rafał Miłecki,
	Srinivas Kandagatla, 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.)

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---

I'm planning to apply this patch to crc-next, since my patch
https://lore.kernel.org/r/20250619183414.100082-3-ebiggers@kernel.org/
depends on this.

 drivers/nvmem/layouts/u-boot-env.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
index 436426d4e8f91..274e8a456e8c1 100644
--- a/drivers/nvmem/layouts/u-boot-env.c
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -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
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvmem: layouts: Switch from crc32() to crc32_le()
  2025-06-20 20:50 [PATCH] nvmem: layouts: Switch from crc32() to crc32_le() Eric Biggers
@ 2025-06-27 10:57 ` Srinivas Kandagatla
  0 siblings, 0 replies; 2+ messages in thread
From: Srinivas Kandagatla @ 2025-06-27 10:57 UTC (permalink / raw)
  To: Eric Biggers, linux-kernel
  Cc: linux-crypto, Ard Biesheuvel, Rafał Miłecki,
	Srinivas Kandagatla



On 6/20/25 9:50 PM, Eric Biggers wrote:
> 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.)
> 
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
> 
> I'm planning to apply this patch to crc-next, since my patch
> https://lore.kernel.org/r/20250619183414.100082-3-ebiggers@kernel.org/
> depends on this.


Acked-by: Srinivas Kandagatla <srini@kernel.org>

--srini

> 
>  drivers/nvmem/layouts/u-boot-env.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
> index 436426d4e8f91..274e8a456e8c1 100644
> --- a/drivers/nvmem/layouts/u-boot-env.c
> +++ b/drivers/nvmem/layouts/u-boot-env.c
> @@ -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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-27 10:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 20:50 [PATCH] nvmem: layouts: Switch from crc32() to crc32_le() Eric Biggers
2025-06-27 10:57 ` Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).