From: Iru Cai Date: Fri, 30 Aug 2019 15:21:40 +0800 Subject: [U-Boot] [PATCH] common/memsize: panic if maxsize is not power of two Message-ID: <20190830072140.GA21544@mylaptop> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de The memory write and recover loop in get_ram_size() work correctly only if maxsize is power of two, otherwise the function will return a small size. Signed-off-by: Iru Cai --- common/memsize.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/memsize.c b/common/memsize.c index 13b0047786..f627149a05 100644 --- a/common/memsize.c +++ b/common/memsize.c @@ -33,6 +33,10 @@ long get_ram_size(long *base, long maxsize) long size; int i = 0; + if ((maxsize & (maxsize - 1)) != 0) { + panic("maxsize must be power of 2!"); + } + for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) { addr = base + cnt; /* pointer arith! */ sync(); -- 2.23.0