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

MIPS: BCM47XX: Make sure NVRAM buffer ends with \0

This will simplify reading its contents.
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/10031/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 2fb7ac5b
...@@ -98,7 +98,7 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim) ...@@ -98,7 +98,7 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n"); pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
if (header->len > NVRAM_SPACE) 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", 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; src = (u32 *)header;
dst = (u32 *)nvram_buf; dst = (u32 *)nvram_buf;
...@@ -106,6 +106,7 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim) ...@@ -106,6 +106,7 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
*dst++ = __raw_readl(src++); *dst++ = __raw_readl(src++);
for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4) for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4)
*dst++ = readl(src++); *dst++ = readl(src++);
nvram_buf[NVRAM_SPACE - 1] = '\0';
return 0; return 0;
} }
...@@ -150,10 +151,10 @@ static int nvram_init(void) ...@@ -150,10 +151,10 @@ static int nvram_init(void)
u8 *dst = (uint8_t *)nvram_buf; u8 *dst = (uint8_t *)nvram_buf;
size_t len = header.len; 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", 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, len);
len = NVRAM_SPACE;
} }
err = mtd_read(mtd, 0, len, &bytes_read, dst); err = mtd_read(mtd, 0, len, &bytes_read, dst);
......
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