linux/drivers/of
Geert Uytterhoeven 2892d8a00d of: Fix truncation of memory sizes on 32-bit platforms
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>
2021-06-16 13:55:05 -06:00
..
unittest-data of: unittest: Statically apply overlays using fdtoverlay 2021-03-23 15:27:51 -06:00
address.c of: Merge of_address_to_resource() and of_pci_address_to_resource() implementations 2021-06-02 20:59:29 -05:00
base.c of: base: Fix spelling issue with function param 'prop' 2021-03-29 13:51:26 -05:00
device.c of: device: Fix function name in header and provide missing descriptions 2021-03-23 15:27:52 -06:00
dynamic.c of: Add missing 'Return' section in kerneldoc comments 2021-03-27 12:59:03 -06:00
fdt.c of: Fix truncation of memory sizes on 32-bit platforms 2021-06-16 13:55:05 -06:00
fdt_address.c of: Use SPDX license tag for DT files 2018-01-08 08:22:45 -06:00
irq.c of: Add missing 'Return' section in kerneldoc comments 2021-03-27 12:59:03 -06:00
Kconfig of: Drop reserved mem dependency on DMA_DECLARE_COHERENT and DMA_CMA 2021-06-02 20:59:28 -05:00
kexec.c kexec: Use fdt_appendprop_addrrange() to add ima buffer to FDT 2021-03-08 12:06:30 -07:00
kobj.c of: Fix a refcounting bug in __of_attach_node_sysfs() 2020-05-27 19:30:25 -06:00
Makefile of: Add a common kexec FDT setup function 2021-03-08 12:06:29 -07:00
of_net.c of: net: fix of_get_mac_addr_nvmem() for non-platform devices 2021-04-13 14:35:02 -07:00
of_numa.c of, numa: Validate some distance map rules 2018-11-08 12:44:34 -06:00
of_private.h of: Move reserved memory private function declarations 2021-06-02 20:59:28 -05:00
of_reserved_mem.c of: Fix truncation of memory sizes on 32-bit platforms 2021-06-16 13:55:05 -06:00
overlay.c of: overlay: Remove redundant assignment to ret 2021-05-03 13:57:56 -05:00
pdt.c of: Remove struct device_node.type pointer 2019-01-10 16:24:44 -06:00
platform.c of: Add missing 'Return' section in kerneldoc comments 2021-03-27 12:59:03 -06:00
property.c Devicetree updates for v5.13: 2021-04-28 15:50:24 -07:00
resolver.c of: overlay: log the error cause on resolver failure 2020-03-02 11:32:44 -06:00
unittest.c of: unittest: Use DEFINE_RES_MEM() to simplify code 2021-06-04 17:29:18 -05:00