summaryrefslogtreecommitdiffstats
path: root/arch/mips/bcm47xx
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2015-05-12 18:46:11 +0200
committerRalf Baechle <ralf@linux-mips.org>2015-06-21 21:52:20 +0200
commitd28c9a55c297db61018744007b6c86abff308751 (patch)
tree501dfa0f48954c1b67a6ebb055244180cb753a70 /arch/mips/bcm47xx
parent2fb7ac5ba680aee0a22bd5cd6fb5c14d248a313d (diff)
downloadtalos-obmc-linux-d28c9a55c297db61018744007b6c86abff308751.tar.gz
talos-obmc-linux-d28c9a55c297db61018744007b6c86abff308751.zip
MIPS: BCM47XX: Make sure NVRAM buffer ends with \0
This will simplify reading its contents. Signed-off-by: Rafał 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/10031/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/bcm47xx')
-rw-r--r--arch/mips/bcm47xx/nvram.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
index ba632ff08a13..dee1c32c0b65 100644
--- a/arch/mips/bcm47xx/nvram.c
+++ b/arch/mips/bcm47xx/nvram.c
@@ -98,7 +98,7 @@ found:
pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
if (header->len > NVRAM_SPACE)
pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
- header->len, NVRAM_SPACE);
+ header->len, NVRAM_SPACE - 1);
src = (u32 *)header;
dst = (u32 *)nvram_buf;
@@ -106,6 +106,7 @@ found:
*dst++ = __raw_readl(src++);
for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4)
*dst++ = readl(src++);
+ nvram_buf[NVRAM_SPACE - 1] = '\0';
return 0;
}
@@ -150,10 +151,10 @@ static int nvram_init(void)
u8 *dst = (uint8_t *)nvram_buf;
size_t len = header.len;
- if (header.len > NVRAM_SPACE) {
+ if (len >= NVRAM_SPACE) {
+ len = NVRAM_SPACE - 1;
pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
- header.len, NVRAM_SPACE);
- len = NVRAM_SPACE;
+ header.len, len);
}
err = mtd_read(mtd, 0, len, &bytes_read, dst);
OpenPOWER on IntegriCloud