linux-yocto/drivers/nvmem
Michael C. Pratt 2d7521aa26 nvmem: layouts: u-boot-env: remove crc32 endianness conversion
On 11 Oct 2022, it was reported that the crc32 verification
of the u-boot environment failed only on big-endian systems
for the u-boot-env nvmem layout driver with the following error.

  Invalid calculated CRC32: 0x88cd6f09 (expected: 0x096fcd88)

This problem has been present since the driver was introduced,
and before it was made into a layout driver.

The suggested fix at the time was to use further endianness
conversion macros in order to have both the stored and calculated
crc32 values to compare always represented in the system's endianness.
This was not accepted due to sparse warnings
and some disagreement on how to handle the situation.
Later on in a newer revision of the patch, it was proposed to use
cpu_to_le32() for both values to compare instead of le32_to_cpu()
and store the values as __le32 type to remove compilation errors.

The necessity of this is based on the assumption that the use of crc32()
requires endianness conversion because the algorithm uses little-endian,
however, this does not prove to be the case and the issue is unrelated.

Upon inspecting the current kernel code,
there already is an existing use of le32_to_cpu() in this driver,
which suggests there already is special handling for big-endian systems,
however, it is big-endian systems that have the problem.

This, being the only functional difference between architectures
in the driver combined with the fact that the suggested fix
was to use the exact same endianness conversion for the values
brings up the possibility that it was not necessary to begin with,
as the same endianness conversion for two values expected to be the same
is expected to be equivalent to no conversion at all.

After inspecting the u-boot environment of devices of both endianness
and trying to remove the existing endianness conversion,
the problem is resolved in an equivalent way as the other suggested fixes.

Ultimately, it seems that u-boot is agnostic to endianness
at least for the purpose of environment variables.
In other words, u-boot reads and writes the stored crc32 value
with the same endianness that the crc32 value is calculated with
in whichever endianness a certain architecture runs on.

Therefore, the u-boot-env driver does not need to convert endianness.
Remove the usage of endianness macros in the u-boot-env driver,
and change the type of local variables to maintain the same return type.

If there is a special situation in the case of endianness,
it would be a corner case and should be handled by a unique "compatible".

Even though it is not necessary to use endianness conversion macros here,
it may be useful to use them in the future for consistent error printing.

Fixes: d5542923f2 ("nvmem: add driver handling U-Boot environment variables")
Reported-by: INAGAKI Hiroshi <musashino.open@gmail.com>
Link: https://lore.kernel.org/all/20221011024928.1807-1-musashino.open@gmail.com
Cc: stable@vger.kernel.org
Signed-off-by: "Michael C. Pratt" <mcpratt@pm.me>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
Link: https://lore.kernel.org/r/20250716144210.4804-1-srini@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-07-16 16:51:04 +02:00
..
layouts nvmem: layouts: u-boot-env: remove crc32 endianness conversion 2025-07-16 16:51:04 +02:00
apple-efuses.c nvmem: add missing MODULE_DESCRIPTION() macros 2024-07-05 09:55:04 +02:00
apple-spmi-nvmem.c nvmem: Add apple-spmi-nvmem driver 2025-05-21 14:28:27 +02:00
bcm-ocotp.c
brcm_nvram.c net, treewide: define and use MAC_ADDR_STR_LEN 2025-03-19 19:17:58 +01:00
core.c nvmem: Remove unused nvmem cell table support 2025-05-21 14:28:27 +02:00
imx-iim.c nvmem: imx-iim: Convert comma to semicolon 2024-11-05 05:33:47 +01:00
imx-ocotp-ele.c nvmem: imx-ocotp: fix MAC address byte length 2025-07-13 17:43:13 +02:00
imx-ocotp-scu.c nvmem: add explicit config option to read old syntax fixed OF cells 2023-10-21 19:19:06 +02:00
imx-ocotp.c nvmem: imx-ocotp: fix MAC address byte length 2025-07-13 17:43:13 +02:00
internals.h nvmem: core: Expose cells through sysfs 2023-12-15 13:30:08 +01:00
jz4780-efuse.c
Kconfig Char/Misc/IIO pull request for 6.16-rc1 2025-06-06 11:50:47 -07:00
lan9662-otpc.c
layerscape-sfp.c
layouts.c nvdimm: Use of_property_present() and of_property_read_bool() 2024-08-21 16:06:43 -05:00
lpc18xx_eeprom.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
lpc18xx_otp.c nvmem: Correct some typos in comments 2024-11-05 05:33:47 +01:00
Makefile Char/Misc/IIO pull request for 6.16-rc1 2025-06-06 11:50:47 -07:00
max77759-nvmem.c nvmem: max77759: Add Maxim MAX77759 NVMEM driver 2025-05-09 15:23:18 +01:00
meson-efuse.c Char/Misc and other driver changes for 6.11-rc1 2024-07-19 15:55:08 -07:00
meson-mx-efuse.c nvmem: meson-mx-efuse: Remove nvmem_device from efuse struct 2024-05-03 07:26:39 +02:00
microchip-otpc.c nvmem: Correct some typos in comments 2024-11-05 05:33:47 +01:00
mtk-efuse.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
mxs-ocotp.c nvmem: Use device_get_match_data() 2023-10-21 19:19:15 +02:00
nintendo-otp.c
qcom-spmi-sdam.c nvmem: qcom-spmi-sdam: Set size in struct nvmem_config 2025-01-10 16:16:48 +01:00
qfprom.c nvmem: qfprom: switch to 4-byte aligned reads 2025-04-11 14:41:22 +02:00
qoriq-efuse.c
rave-sp-eeprom.c nvmem: add explicit config option to read old syntax fixed OF cells 2023-10-21 19:19:06 +02:00
rcar-efuse.c nvmem: Add R-Car E-FUSE driver 2024-11-05 05:33:46 +01:00
rmem.c nvmem: rmem: add CRC validation for Mobileye EyeQ5 NVMEM 2024-12-30 15:36:00 +01:00
rockchip-efuse.c nvmem: rockchip-efuse: set type to OTP 2024-07-05 09:55:04 +02:00
rockchip-otp.c nvmem: rockchip-otp: add rk3576 variant data 2025-04-11 14:41:21 +02:00
sc27xx-efuse.c nvmem: sc27xx: fix module autoloading 2024-05-03 07:26:38 +02:00
sec-qfprom.c nvmem: add explicit config option to read old syntax fixed OF cells 2023-10-21 19:19:06 +02:00
snvs_lpgpr.c
sprd-efuse.c nvmem: sprd: fix module autoloading 2024-05-03 07:26:38 +02:00
stm32-bsec-optee-ta.c
stm32-bsec-optee-ta.h
stm32-romem.c nvmem: stm32: add support for STM32MP25 BSEC to control OTP data 2023-12-15 13:30:08 +01:00
sunplus-ocotp.c nvmem: sunplus-ocotp: Use devm_platform_ioremap_resource_byname() helper function 2024-09-03 12:13:23 +02:00
sunxi_sid.c nvmem: add explicit config option to read old syntax fixed OF cells 2023-10-21 19:19:06 +02:00
u-boot-env.c nvmem: layouts: add U-Boot env layout 2024-09-11 16:05:15 +02:00
uniphier-efuse.c nvmem: add explicit config option to read old syntax fixed OF cells 2023-10-21 19:19:06 +02:00
vf610-ocotp.c
zynqmp_nvmem.c nvmem: zynqmp_nvmem: unbreak driver after cleanup 2025-05-21 14:28:11 +02:00