032-01-MIPS-BCM47XX-Make-sure-NVRAM-buffer-ends-with-0.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. This will simplify reading its contents.
  9. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  10. Cc: linux-mips@linux-mips.org
  11. Cc: Hauke Mehrtens <hauke@hauke-m.de>
  12. Cc: Hante Meuleman <meuleman@broadcom.com>
  13. Cc: Ian Kent <raven@themaw.net>
  14. Patchwork: https://patchwork.linux-mips.org/patch/10031/
  15. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  16. ---
  17. arch/mips/bcm47xx/nvram.c | 9 +++++----
  18. 1 file changed, 5 insertions(+), 4 deletions(-)
  19. --- a/arch/mips/bcm47xx/nvram.c
  20. +++ b/arch/mips/bcm47xx/nvram.c
  21. @@ -98,7 +98,7 @@ found:
  22. pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
  23. if (header->len > NVRAM_SPACE)
  24. pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
  25. - header->len, NVRAM_SPACE);
  26. + header->len, NVRAM_SPACE - 1);
  27. src = (u32 *)header;
  28. dst = (u32 *)nvram_buf;
  29. @@ -106,6 +106,7 @@ found:
  30. *dst++ = __raw_readl(src++);
  31. for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4)
  32. *dst++ = readl(src++);
  33. + nvram_buf[NVRAM_SPACE - 1] = '\0';
  34. return 0;
  35. }
  36. @@ -150,10 +151,10 @@ static int nvram_init(void)
  37. u8 *dst = (uint8_t *)nvram_buf;
  38. size_t len = header.len;
  39. - if (header.len > NVRAM_SPACE) {
  40. + if (len >= NVRAM_SPACE) {
  41. + len = NVRAM_SPACE - 1;
  42. pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
  43. - header.len, NVRAM_SPACE);
  44. - len = NVRAM_SPACE;
  45. + header.len, len);
  46. }
  47. err = mtd_read(mtd, 0, len, &bytes_read, dst);