Commit 5bfad4ee authored by Rafał Miłecki's avatar Rafał Miłecki Committed by Ralf Baechle

MIPS: BCM47XX: Simplify function looking for NVRAM entry

First of all it shouldn't modify copied NVRAM just to make sure it can
loop over all entries. It's enough to just compare current position
pointer with the end of buffer address.
Secondly buffer is guaranteed to be \0 ended, so we don't need strnchr.
Signed-off-by: default avatarRafał Miłecki <zajec5@gmail.com>
Cc: linux-mips@linux-mips.org
Cc: Hauke Mehrtens <hauke@hauke-m.de>
Cc: Hante Meuleman <meuleman@broadcom.com>
Cc: Ian Kent <raven@themaw.net>
Patchwork: https://patchwork.linux-mips.org/patch/10032/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent d28c9a55
...@@ -171,7 +171,7 @@ static int nvram_init(void) ...@@ -171,7 +171,7 @@ static int nvram_init(void)
int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
{ {
char *var, *value, *end, *eq; char *var, *value, *end, *eq;
int data_left, err; int err;
if (!name) if (!name)
return -EINVAL; return -EINVAL;
...@@ -184,19 +184,16 @@ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) ...@@ -184,19 +184,16 @@ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
/* Look for name=value and return value */ /* Look for name=value and return value */
var = &nvram_buf[sizeof(struct nvram_header)]; var = &nvram_buf[sizeof(struct nvram_header)];
end = nvram_buf + sizeof(nvram_buf) - 2; end = nvram_buf + sizeof(nvram_buf);
end[0] = '\0'; while (var < end && *var) {
end[1] = '\0'; eq = strchr(var, '=');
for (; *var; var = value + strlen(value) + 1) {
data_left = end - var;
eq = strnchr(var, data_left, '=');
if (!eq) if (!eq)
break; break;
value = eq + 1; value = eq + 1;
if (eq - var == strlen(name) && if (eq - var == strlen(name) &&
strncmp(var, name, eq - var) == 0) strncmp(var, name, eq - var) == 0)
return snprintf(val, val_len, "%s", value); return snprintf(val, val_len, "%s", value);
var = value + strlen(value) + 1;
} }
return -ENOENT; return -ENOENT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment