diff mbox

[U-Boot] fix get_ram_size memory corruption

Message ID 1413874945-16560-1-git-send-email-kraxel@redhat.com
State Rejected
Delegated to: Tom Rini
Headers show

Commit Message

Gerd Hoffmann Oct. 21, 2014, 7:02 a.m. UTC
base[0] is saved, but never restored.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 common/memsize.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Wolfgang Denk Oct. 21, 2014, 9:27 a.m. UTC | #1
Dear Gerd,

In message <1413874945-16560-1-git-send-email-kraxel@redhat.com> you wrote:
> base[0] is saved, but never restored.

Patches for this have been submitted before, but were rejected.  You
may want to dig the archives for these.

What exactly is your test case where you see any memory corruption?


> -	if ((val = *addr) != 0) {
> +	val = *addr;
> +	*addr = save[i];
> +	if ((val = 0) != 0) {
--------^^^^^^^^^^^^^^^^^^^^^^

This code looks pretty much wrong to me; the condition "0 != 0" can
never become true...

NAK.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/common/memsize.c b/common/memsize.c
index 589400d..8bda2ba 100644
--- a/common/memsize.c
+++ b/common/memsize.c
@@ -48,7 +48,9 @@  long get_ram_size(long *base, long maxsize)
 	*addr = 0;
 
 	sync ();
-	if ((val = *addr) != 0) {
+	val = *addr;
+	*addr = save[i];
+	if ((val = 0) != 0) {
 		/* Restore the original data before leaving the function.
 		 */
 		sync ();