Skip to contentSkip to conversation

common/memsize: panic if maxsize is not power of two

PATCH New Iru Cai 2 participants 2 messages Aug 30, 2019 – Oct 11, 2019

lore
Share & tools
lore

Iru Cai

author
#0 lore raw

PATCH 1/1 common/memsize: panic if maxsize is not power of two

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.

---
 common/memsize.c | 4 ++++
 1 file changed, 4 insertions(+)
common/memsize.c +4 -0
index 13b0047786..f627149a05 100644
@@ -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();
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/1 common/memsize: panic if maxsize is not power of two

Quoted 14 lines · Iru Cai

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.

---
 common/memsize.c | 4 ++++
 1 file changed, 4 insertions(+)
common/memsize.c +0 -0
index 13b0047786..f627149a05 100644

common/memsize.c long get_ram_size(long *base, long maxsize) · line 42

Quoted 10 lines
common/memsize.c +4 -0
@@ -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!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191011/9381ce2b/attachment.sig>