1 From 7180de9a27ce433efc15bc1982b9a9e4ba3c48dc Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Sat, 10 Nov 2012 02:04:58 +0100
4 Subject: [PATCH] MIPS: BCM63XX: fix nvram checksum calculation
6 The current checksum calculation code does nothing except checking that
7 the first byte of nvram is 0 without actually checking the checksum.
9 Implement the correct checksum calculation by calculating the crc32 with
10 the checksum field set to 0.
12 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
15 This patch depends on the previous nvram patch ("move nvram functions
16 into their own file").
18 arch/mips/bcm63xx/nvram.c | 23 +++++++++++++----------
19 1 files changed, 13 insertions(+), 10 deletions(-)
21 --- a/arch/mips/bcm63xx/nvram.c
22 +++ b/arch/mips/bcm63xx/nvram.c
24 #define pr_fmt(fmt) "bcm63xx_nvram: " fmt
26 #include <linux/init.h>
27 +#include <linux/crc32.h>
28 #include <linux/export.h>
29 #include <linux/kernel.h>
30 #include <linux/if_ether.h>
31 @@ -40,23 +41,25 @@ static int mac_addr_used;
32 int __init bcm63xx_nvram_init(void *addr)
34 unsigned int check_len;
37 + u32 crc, expected_crc;
39 /* extract nvram data */
40 memcpy(&nvram, addr, sizeof(nvram));
42 /* check checksum before using data */
43 - if (nvram.version <= 4)
44 - check_len = offsetof(struct bcm963xx_nvram, checksum_old);
46 + if (nvram.version <= 4) {
47 + check_len = offsetof(struct bcm963xx_nvram, reserved3);
48 + expected_crc = nvram.checksum_old;
49 + nvram.checksum_old = 0;
51 check_len = sizeof(nvram);
54 + expected_crc = nvram.checksum_high;
55 + nvram.checksum_high = 0;
61 + crc = crc32_le(~0, (u8 *)&nvram, check_len);
63 + if (crc != expected_crc)