cmd_mem: cleanups, catch bad usage
Currently, memtest will silently accept bad data. Perform error checking on user intput. Signed-off-by: Pavel Machek <pavel@denx.de>
This commit is contained in:
		
							parent
							
								
									8f6e18385a
								
							
						
					
					
						commit
						e37f1eb45c
					
				|  | @ -999,10 +999,10 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, | ||||||
| { | { | ||||||
| 	ulong start, end; | 	ulong start, end; | ||||||
| 	vu_long *buf, *dummy; | 	vu_long *buf, *dummy; | ||||||
| 	int iteration_limit; | 	int iteration_limit = 0; | ||||||
| 	int ret; | 	int ret; | ||||||
| 	ulong errs = 0;	/* number of errors, or -1 if interrupted */ | 	ulong errs = 0;	/* number of errors, or -1 if interrupted */ | ||||||
| 	ulong pattern; | 	ulong pattern = 0; | ||||||
| 	int iteration; | 	int iteration; | ||||||
| #if defined(CONFIG_SYS_ALT_MEMTEST) | #if defined(CONFIG_SYS_ALT_MEMTEST) | ||||||
| 	const int alt_test = 1; | 	const int alt_test = 1; | ||||||
|  | @ -1010,25 +1010,29 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, | ||||||
| 	const int alt_test = 0; | 	const int alt_test = 0; | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 	if (argc > 1) |  | ||||||
| 		start = simple_strtoul(argv[1], NULL, 16); |  | ||||||
| 	else |  | ||||||
| 	start = CONFIG_SYS_MEMTEST_START; | 	start = CONFIG_SYS_MEMTEST_START; | ||||||
| 
 |  | ||||||
| 	if (argc > 2) |  | ||||||
| 		end = simple_strtoul(argv[2], NULL, 16); |  | ||||||
| 	else |  | ||||||
| 	end = CONFIG_SYS_MEMTEST_END; | 	end = CONFIG_SYS_MEMTEST_END; | ||||||
| 
 | 
 | ||||||
|  | 	if (argc > 1) | ||||||
|  | 		if (strict_strtoul(argv[1], 16, &start) < 0) | ||||||
|  | 			return CMD_RET_USAGE; | ||||||
|  | 
 | ||||||
|  | 	if (argc > 2) | ||||||
|  | 		if (strict_strtoul(argv[2], 16, &end) < 0) | ||||||
|  | 			return CMD_RET_USAGE; | ||||||
|  | 
 | ||||||
| 	if (argc > 3) | 	if (argc > 3) | ||||||
| 		pattern = (ulong)simple_strtoul(argv[3], NULL, 16); | 		if (strict_strtoul(argv[3], 16, &pattern) < 0) | ||||||
| 	else | 			return CMD_RET_USAGE; | ||||||
| 		pattern = 0; |  | ||||||
| 
 | 
 | ||||||
| 	if (argc > 4) | 	if (argc > 4) | ||||||
| 		iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16); | 		if (strict_strtoul(argv[4], 16, &iteration_limit) < 0) | ||||||
| 	else | 			return CMD_RET_USAGE; | ||||||
| 		iteration_limit = 0; | 
 | ||||||
|  | 	if (end < start) { | ||||||
|  | 		printf("Refusing to do empty test\n"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	printf("Testing %08x ... %08x:\n", (uint)start, (uint)end); | 	printf("Testing %08x ... %08x:\n", (uint)start, (uint)end); | ||||||
| 	debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, | 	debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, | ||||||
|  | @ -1079,7 +1083,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, | ||||||
| 		ret = errs != 0; | 		ret = errs != 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return ret;	/* not reached */ | 	return ret; | ||||||
| } | } | ||||||
| #endif	/* CONFIG_CMD_MEMTEST */ | #endif	/* CONFIG_CMD_MEMTEST */ | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue