05b6d2d42e05044efe8f7ca36c20ada9663675f0
[openwrt.git] / target / linux / brcm47xx / patches-4.0 / 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 diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
23 index ba632ff..dee1c32 100644
24 --- a/arch/mips/bcm47xx/nvram.c
25 +++ b/arch/mips/bcm47xx/nvram.c
26 @@ -98,7 +98,7 @@ found:
27                 pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
28         if (header->len > NVRAM_SPACE)
29                 pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
30 -                      header->len, NVRAM_SPACE);
31 +                      header->len, NVRAM_SPACE - 1);
32  
33         src = (u32 *)header;
34         dst = (u32 *)nvram_buf;
35 @@ -106,6 +106,7 @@ found:
36                 *dst++ = __raw_readl(src++);
37         for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4)
38                 *dst++ = readl(src++);
39 +       nvram_buf[NVRAM_SPACE - 1] = '\0';
40  
41         return 0;
42  }
43 @@ -150,10 +151,10 @@ static int nvram_init(void)
44                 u8 *dst = (uint8_t *)nvram_buf;
45                 size_t len = header.len;
46  
47 -               if (header.len > NVRAM_SPACE) {
48 +               if (len >= NVRAM_SPACE) {
49 +                       len = NVRAM_SPACE - 1;
50                         pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
51 -                               header.len, NVRAM_SPACE);
52 -                       len = NVRAM_SPACE;
53 +                               header.len, len);
54                 }
55  
56                 err = mtd_read(mtd, 0, len, &bytes_read, dst);
57 -- 
58 1.8.4.5
59