7577da10a854d585e680b8bdb8d1a948f74bb685
[openwrt/openwrt.git] / target / linux / brcm47xx / patches-4.1 / 031-01-MIPS-BCM47XX-Make-sure-NVRAM-buffer-ends-with-0.patch
1 From 4ddb225376a2802a4e20e16f71c6d37b679e3169 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Tue, 12 May 2015 18:46:11 +0200
4 Subject: [PATCH] MIPS: BCM47XX: Make sure NVRAM buffer ends with \0
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This will simplify reading its contents.
10
11 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
12 Cc: linux-mips@linux-mips.org
13 Cc: Hauke Mehrtens <hauke@hauke-m.de>
14 Cc: Hante Meuleman <meuleman@broadcom.com>
15 Cc: Ian Kent <raven@themaw.net>
16 Patchwork: https://patchwork.linux-mips.org/patch/10031/
17 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
18 ---
19 arch/mips/bcm47xx/nvram.c | 9 +++++----
20 1 file changed, 5 insertions(+), 4 deletions(-)
21
22 --- a/arch/mips/bcm47xx/nvram.c
23 +++ b/arch/mips/bcm47xx/nvram.c
24 @@ -98,7 +98,7 @@ found:
25 pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
26 if (header->len > NVRAM_SPACE)
27 pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
28 - header->len, NVRAM_SPACE);
29 + header->len, NVRAM_SPACE - 1);
30
31 src = (u32 *)header;
32 dst = (u32 *)nvram_buf;
33 @@ -106,6 +106,7 @@ found:
34 *dst++ = __raw_readl(src++);
35 for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4)
36 *dst++ = readl(src++);
37 + nvram_buf[NVRAM_SPACE - 1] = '\0';
38
39 return 0;
40 }
41 @@ -150,10 +151,10 @@ static int nvram_init(void)
42 u8 *dst = (uint8_t *)nvram_buf;
43 size_t len = header.len;
44
45 - if (header.len > NVRAM_SPACE) {
46 + if (len >= NVRAM_SPACE) {
47 + len = NVRAM_SPACE - 1;
48 pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
49 - header.len, NVRAM_SPACE);
50 - len = NVRAM_SPACE;
51 + header.len, len);
52 }
53
54 err = mtd_read(mtd, 0, len, &bytes_read, dst);