]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - lib/lmb.c
lib: lmb: fix overflow in __lmb_alloc_base w/ large RAM
[karo-tx-uboot.git] / lib / lmb.c
index 49a3c9e01e59d15152660d00847a825c33575d4b..41a2be463565c6b519841902cba45b43839ef69a 100644 (file)
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -295,7 +295,10 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, phy
                if (max_addr == LMB_ALLOC_ANYWHERE)
                        base = lmb_align_down(lmbbase + lmbsize - size, align);
                else if (lmbbase < max_addr) {
-                       base = min(lmbbase + lmbsize, max_addr);
+                       base = lmbbase + lmbsize;
+                       if (base < lmbbase)
+                               base = -1;
+                       base = min(base, max_addr);
                        base = lmb_align_down(base - size, align);
                } else
                        continue;