diff mbox series

[U-Boot] common/memsize: panic if maxsize is not power of two

Message ID 20190830072140.GA21544@mylaptop
State Changes Requested
Delegated to: Tom Rini
Headers show
Series [U-Boot] common/memsize: panic if maxsize is not power of two | expand

Commit Message

Iru Cai Aug. 30, 2019, 7:21 a.m. UTC
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 <mytbk920423@gmail.com>
---
 common/memsize.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Tom Rini Oct. 11, 2019, 5:08 p.m. UTC | #1
On Fri, Aug 30, 2019 at 03:21:40PM +0800, Iru Cai wrote:

> 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 <mytbk920423@gmail.com>
> ---
>  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();

The first problem is that this causes cl-som-imx7 to fail to link due to
missing a reference to reset_cpu().  The second problem is, we're
increasing everyone with a new string included.  Is this a problem that
can really be found outside of development (and so caught and memory
init fixed) or is something else going on here?  Thanks!
diff mbox series

Patch

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();