[ar71xx] fix handling of invalid arguments passed by some bootloaders (thanks to...
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / prom.c
index 005d84acf93f80bbe48769ddd233a3393c4692f9..5402e0a54389ace0337ca3e11a1428a7fbf60a90 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  Atheros AR71xx SoC specific prom routines
  *
- *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
+ *  Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  *
  *  This program is free software; you can redistribute it and/or modify it
@@ -58,21 +58,46 @@ static struct board_rec boards[] __initdata = {
        }, {
                .name           = "UBNT-LSX",
                .mach_type      = AR71XX_MACH_UBNT_LSX,
+       }, {
+               .name           = "WNR2000",
+               .mach_type      = AR71XX_MACH_WNR2000,
+       }, {
+               .name           = "PB42",
+               .mach_type      = AR71XX_MACH_PB42,
+       }, {
+               .name           = "MZK-W300NH",
+               .mach_type      = AR71XX_MACH_MZK_W300NH,
+       }, {
+               .name           = "MZK-W04NU",
+               .mach_type      = AR71XX_MACH_MZK_W04NU,
        }
 };
 
+static inline int is_valid_ram_addr(void *addr)
+{
+       if (((u32) addr > KSEG0) &&
+           ((u32) addr < (KSEG0 + AR71XX_MEM_SIZE_MAX)))
+               return 1;
+
+       if (((u32) addr > KSEG1) &&
+           ((u32) addr < (KSEG1 + AR71XX_MEM_SIZE_MAX)))
+               return 1;
+
+       return 0;
+}
+
 static __init char *ar71xx_prom_getargv(const char *name)
 {
        int len = strlen(name);
        int i;
 
-       if (!ar71xx_prom_argv)
+       if (!is_valid_ram_addr(ar71xx_prom_argv))
                return NULL;
 
        for (i = 0; i < ar71xx_prom_argc; i++) {
                char *argv = ar71xx_prom_argv[i];
 
-               if (!argv)
+               if (!is_valid_ram_addr(argv))
                        continue;
 
                if (strncmp(name, argv, len) == 0 && (argv)[len] == '=')
@@ -87,10 +112,10 @@ static __init char *ar71xx_prom_getenv(const char *envname)
        int len = strlen(envname);
        char **env;
 
-       if (!ar71xx_prom_envp)
+       if (!is_valid_ram_addr(ar71xx_prom_envp))
                return NULL;
 
-       for (env = ar71xx_prom_envp; *env != NULL; env++)
+       for (env = ar71xx_prom_envp; is_valid_ram_addr(*env); env++)
                if (strncmp(envname, *env, len) == 0 && (*env)[len] == '=')
                        return *env + len + 1;