[U-Boot-Users] Re: [PATCH] !CFG_MEMTEST_SCRATCH - do not dereference NULL

Ladislav Michl ladis at linux-mips.org
Mon Nov 29 16:19:14 CET 2004


On Mon, Nov 29, 2004 at 03:33:16PM +0100, Anders Larsen wrote:
> "VanBaren, Gerald (AGRE)" <Gerald.VanBaren at smiths-aerospace.com>:
> >The proper fix is, for your board, change
> >the assignment "vu_long *dummy = 0x00000000;" to point to writable RAM
> >on your board.
> 
> This is the purpose of CFG_MEMTEST_SCRATCH.
> 
> Please, please read the README, which says:
> "- CFG_MEMTEST_SCRATCH:
>    Scratch address used by the alternate memory test
>    You only need to set this if address zero isn't writeable"

Ah, sorry. I looked only at code and it seemed wrong to me. See below.

> The last statement implies that you DO need to set
> CFG_MEMTEST_SCRATCH if address zero ISN'T writeable.
> 
> No need to change any code at all.

Thanks, now I see the code works how author intended. But I do not agree
with the way how it is written. NULL pointer means invalid pointer,
while "vu_long *dummy = 0x00000000;" means valid pointer to address
zero (and yes I know they both will lead to the same machine code ;-))
Consider patch bellow. 

Now a little question. Would you mind a patch making scratch area
optional?

Regards,
	ladis

Index: common/cmd_mem.c
===================================================================
RCS file: /cvsroot/u-boot/u-boot/common/cmd_mem.c,v
retrieving revision 1.19
diff -u -r1.19 cmd_mem.c
--- common/cmd_mem.c	10 Oct 2004 23:27:33 -0000	1.19
+++ common/cmd_mem.c	29 Nov 2004 15:14:40 -0000
@@ -646,8 +646,8 @@
 	vu_long	num_words;
 #if defined(CFG_MEMTEST_SCRATCH)
 	vu_long *dummy = (vu_long*)CFG_MEMTEST_SCRATCH;
-#else
-	vu_long *dummy = NULL;
+#else	/* Undefined if address zero is writeable */
+	vu_long *dummy = (vu_long*)0x00000000;
 #endif
 	int	j;
 	int iterations = 1;




More information about the U-Boot mailing list