u-boot-brain/drivers/core
Marek Behún 364bef150d regmap: fix a serious pointer casting bug
There is a serious bug in regmap_read() and regmap_write() functions
where an uint pointer is cast to (void *) which is then cast to (u8 *),
(u16 *), (u32 *) or (u64 *), depending on register width of the map.

For example given a regmap with 16-bit register width the code
	int val = 0x12340000;
	regmap_read(map, 0, &val);
only changes the lower 16 bits of val on little-endian machines.
The upper 16 bits will remain 0x1234.

Nobody noticed this probably because this bug can be triggered with
regmap_write() only on big-endian architectures (which are not used by
many people anymore), and on little endian this bug has consequences
only if register width is 8 or 16 bits and also the memory place to
which regmap_read() should store it's result has non-zero upper bits,
which it seems doesn't happen anywhere in U-Boot normally. CI managed to
trigger this bug in unit test of dm_test_devm_regmap_field when compiled
for sandbox_defconfig using LTO.

Fix this by utilizing an union { u8; u16; u32; u64; } and reading data
into this union / writing data from this union.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Cc: Simon Glass <sjg@chromium.org>
Cc: Heiko Schocher <hs@denx.de>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Pratyush Yadav <p.yadav@ti.com>
2021-05-24 14:21:30 -04:00
..
acpi.c dm: core: Use -ENOSPC in acpi_get_path() 2021-04-06 16:33:19 +12:00
device-remove.c Merge branch '2021-02-02-drop-asm_global_data-when-unused' 2021-02-15 10:16:45 -05:00
device.c dm: core: Use separate priv/plat data region 2021-03-26 17:03:09 +13:00
devres.c dm: core: Access device flags through functions 2021-01-05 12:24:41 -07:00
dump.c dm: core: Access device flags through functions 2021-01-05 12:24:41 -07:00
fdtaddr.c Revert "fdt: translate address if #size-cells = <0>" 2021-05-12 16:27:57 +05:30
Kconfig Revert "fdt: translate address if #size-cells = <0>" 2021-05-12 16:27:57 +05:30
lists.c dm: core: Add logging when lists_bind_fdt() fails 2021-01-05 12:24:41 -07:00
Makefile dm: Avoid using #ifdef for CONFIG_OF_LIVE 2020-10-29 14:42:17 -06:00
of_access.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
of_addr.c Revert "fdt: translate address if #size-cells = <0>" 2021-05-12 16:27:57 +05:30
of_extra.c of: extra: Introduce ofnode_phy_is_fixed_link() API 2021-04-15 14:22:17 +05:30
ofnode.c Revert "fdt: translate address if #size-cells = <0>" 2021-05-12 16:27:57 +05:30
read_extra.c SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
read.c dm: Introduce xxx_get_dma_range() 2021-02-18 11:56:25 +01:00
regmap.c regmap: fix a serious pointer casting bug 2021-05-24 14:21:30 -04:00
root.c Revert "fdt: translate address if #size-cells = <0>" 2021-05-12 16:27:57 +05:30
simple-bus.c dm: core: Correctly read <ranges> of simple-bus 2021-04-15 14:22:17 +05:30
simple-pm-bus.c simple-pm-bus: Use -ENOSYS for checking missing system call 2021-04-06 16:33:19 +12:00
syscon-uclass.c dm: treewide: Rename ..._platdata variables to just ..._plat 2020-12-13 16:51:09 -07:00
uclass.c dm: core: Drop uclass_find_device_by_phandle() with of-platdata 2021-03-26 17:03:08 +13:00
util.c dm: core: Allow dm_warn() to be used in SPL 2020-10-29 14:42:17 -06:00