linux-stable/drivers/of
Geert Uytterhoeven 193dc44179 of: Fix truncation of memory sizes on 32-bit platforms
[ Upstream commit 2892d8a00d ]

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-20 16:15:57 +02:00
..
unittest-data of/unittest: Fix I2C bus unit-address error 2019-11-20 18:47:00 +01:00
address.c of/address: Fix of_node memory leak in of_dma_is_coherent 2020-11-18 19:18:48 +01:00
base.c of: make PowerMac cache node search conditional on CONFIG_PPC_PMAC 2019-11-20 18:46:06 +01:00
device.c
dynamic.c
fdt.c of: Fix truncation of memory sizes on 32-bit platforms 2021-07-20 16:15:57 +02:00
fdt_address.c
irq.c
Kconfig of: Add OF_DMA_DEFAULT_COHERENT & select it on powerpc 2020-02-11 04:34:03 -08:00
kobj.c of: Fix a refcounting bug in __of_attach_node_sysfs() 2020-06-25 15:33:00 +02:00
Makefile
of_mdio.c of: of_mdio: Correct loop scanning logic 2020-07-22 09:32:03 +02:00
of_net.c
of_numa.c
of_private.h
of_reserved_mem.c of: Fix truncation of memory sizes on 32-bit platforms 2021-07-20 16:15:57 +02:00
overlay.c of: overlay: kmemleak in dup_and_fixup_symbol_prop() 2020-04-23 10:30:14 +02:00
pdt.c
platform.c
property.c
resolver.c
unittest.c of: unittest: kmemleak in of_unittest_overlay_high_level() 2020-04-23 10:30:14 +02:00