From: Atish Patra <atish.patra@wdc.com>
Date: Tue, 21 Apr 2020 18:15:00 +0000 (-0700)
Subject: fdtdec: Fix boundary check
X-Git-Tag: v2025.01-rc5-pxa1908~2464^2~4
X-Git-Url: http://git.dujemihanovic.xyz/img/%22http:/www.sics.se/static/gitweb.css?a=commitdiff_plain;h=f614753c4b91bc3b56809773aeb17da10f1231a5;p=u-boot.git

fdtdec: Fix boundary check

In U-Boot, the reserved memory end address is considered as a inclusive
address. This notion is followed while adding a reserved memory node to
the DT.

For example:
end_address = start_address + size - 1

Follow the same notion and fix the end address computation while checking
for existing nodes.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
---

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 9ecfa2a2d7..460f0d250b 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1311,7 +1311,8 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,
 			continue;
 		}
 
-		if (addr == carveout->start && (addr + size) == carveout->end) {
+		if (addr == carveout->start && (addr + size - 1) ==
+						carveout->end) {
 			if (phandlep)
 				*phandlep = fdt_get_phandle(blob, node);
 			return 0;