From 5dcf53c610633ccaf3316181f084fd1069715179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 5 Jun 2015 20:41:18 +0000 Subject: brcm47xx: backport MIPS BCM47XX changes queued for 4.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Miłecki git-svn-id: svn://svn.openwrt.org/openwrt/trunk@45906 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- ...X-Simplify-function-looking-for-NVRAM-ent.patch | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 target/linux/brcm47xx/patches-4.0/031-02-MIPS-BCM47XX-Simplify-function-looking-for-NVRAM-ent.patch (limited to 'target/linux/brcm47xx/patches-4.0/031-02-MIPS-BCM47XX-Simplify-function-looking-for-NVRAM-ent.patch') diff --git a/target/linux/brcm47xx/patches-4.0/031-02-MIPS-BCM47XX-Simplify-function-looking-for-NVRAM-ent.patch b/target/linux/brcm47xx/patches-4.0/031-02-MIPS-BCM47XX-Simplify-function-looking-for-NVRAM-ent.patch new file mode 100644 index 0000000000..c74bd06495 --- /dev/null +++ b/target/linux/brcm47xx/patches-4.0/031-02-MIPS-BCM47XX-Simplify-function-looking-for-NVRAM-ent.patch @@ -0,0 +1,64 @@ +From f6f895644230b13618f14f7108f9b23a21a87bfa Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Tue, 12 May 2015 18:46:12 +0200 +Subject: [PATCH] MIPS: BCM47XX: Simplify function looking for NVRAM entry +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +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: Rafał Miłecki +Cc: linux-mips@linux-mips.org +Cc: Hauke Mehrtens +Cc: Hante Meuleman +Cc: Ian Kent +Patchwork: https://patchwork.linux-mips.org/patch/10032/ +Signed-off-by: Ralf Baechle +--- + arch/mips/bcm47xx/nvram.c | 13 +++++-------- + 1 file changed, 5 insertions(+), 8 deletions(-) + +diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c +index dee1c32..95d028c 100644 +--- a/arch/mips/bcm47xx/nvram.c ++++ b/arch/mips/bcm47xx/nvram.c +@@ -171,7 +171,7 @@ static int nvram_init(void) + int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) + { + char *var, *value, *end, *eq; +- int data_left, err; ++ int err; + + if (!name) + return -EINVAL; +@@ -184,19 +184,16 @@ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) + + /* Look for name=value and return value */ + var = &nvram_buf[sizeof(struct nvram_header)]; +- end = nvram_buf + sizeof(nvram_buf) - 2; +- end[0] = '\0'; +- end[1] = '\0'; +- for (; *var; var = value + strlen(value) + 1) { +- data_left = end - var; +- +- eq = strnchr(var, data_left, '='); ++ end = nvram_buf + sizeof(nvram_buf); ++ while (var < end && *var) { ++ eq = strchr(var, '='); + if (!eq) + break; + value = eq + 1; + if (eq - var == strlen(name) && + strncmp(var, name, eq - var) == 0) + return snprintf(val, val_len, "%s", value); ++ var = value + strlen(value) + 1; + } + return -ENOENT; + } +-- +1.8.4.5 + -- cgit v1.2.3