kernel_optimize_test/drivers/of
Geert Uytterhoeven f929d21af7 of: Fix truncation of memory sizes on 32-bit platforms
[ Upstream commit 2892d8a00d23d511a0591ac4b2ff3f050ae1f004 ]

Variable "size" has type "phys_addr_t", which can be either 32-bit or
64-bit on 32-bit systems, while "unsigned long" is always 32-bit on
32-bit systems.  Hence the cast in

    (unsigned long)size / SZ_1M

may truncate a 64-bit size to 32-bit, as casts have a higher operator
precedence than divisions.

Fix this by inverting the order of the cast and division, which should
be safe for memory blocks smaller than 4 PiB.  Note that the division is
actually a shift, as SZ_1M is a power-of-two constant, hence there is no
need to use div_u64().

While at it, use "%lu" to format "unsigned long".

Fixes: e8d9d1f548 ("drivers: of: add initialization code for static reserved memory")
Fixes: 3f0c820664 ("drivers: of: add initialization code for dynamic reserved memory")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/4a1117e72d13d26126f57be034c20dac02f1e915.1623835273.git.geert+renesas@glider.be
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-07-14 16:56:46 +02:00
..
unittest-data of: unittest: Use bigger address cells to catch parser regressions 2020-08-03 16:24:49 -06:00
address.c of/address: Introduce of_dma_get_max_cpu_address() 2021-03-09 11:11:13 +01:00
base.c of: Export of_remove_property() to modules 2020-09-05 13:09:03 -07:00
device.c of/device: Update dma_range_map only when dev has valid dma-ranges 2021-02-03 23:28:50 +01:00
dynamic.c of: of_detach_node() remove unneeded local return variable 2020-04-14 07:59:54 -05:00
fdt_address.c
fdt.c of: Fix truncation of memory sizes on 32-bit platforms 2021-07-14 16:56:46 +02:00
irq.c of/irq: Make of_msi_map_rid() PCI bus agnostic 2020-07-28 15:51:32 +01:00
Kconfig net: phy: Move of_mdio from drivers/of to drivers/net/mdio 2020-10-10 10:55:05 -07:00
kobj.c of: Fix a refcounting bug in __of_attach_node_sysfs() 2020-05-27 19:30:25 -06:00
Makefile net: phy: Move of_mdio from drivers/of to drivers/net/mdio 2020-10-10 10:55:05 -07:00
of_net.c net: of_get_phy_mode: Change API to solve int/unit warnings 2019-11-04 11:21:25 -08:00
of_numa.c
of_private.h dma-mapping: introduce DMA range map, supplanting dma_pfn_offset 2020-09-17 18:43:56 +02:00
of_reserved_mem.c of: Fix truncation of memory sizes on 32-bit platforms 2021-07-14 16:56:46 +02:00
overlay.c of: overlay: fix for_each_child.cocci warnings 2021-05-14 09:50:24 +02:00
pdt.c of: Remove struct device_node.type pointer 2019-01-10 16:24:44 -06:00
platform.c of: platform: Destroy child devices symmetrically 2020-08-17 20:19:35 -06:00
property.c of: property: fw_devlink: do not link ".*,nr-gpios" 2021-04-14 08:41:58 +02:00
resolver.c of: overlay: log the error cause on resolver failure 2020-03-02 11:32:44 -06:00
unittest.c of: unittest: Fix build on architectures without CONFIG_OF_ADDRESS 2021-03-09 11:11:15 +01:00