kernel: add md5sum for 3.9 final
[oweals/openwrt.git] / target / linux / brcm63xx / patches-3.7 / 005-MIPS-BCM63XX-fix-nvram-checksum-calculation.patch
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
5
6 The current checksum calculation code does nothing except checking that
7 the first byte of nvram is 0 without actually checking the checksum.
8
9 Implement the correct checksum calculation by calculating the crc32 with
10 the checksum field set to 0.
11
12 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
13 ---
14
15 This patch depends on the previous nvram patch ("move nvram functions
16 into their own file").
17
18  arch/mips/bcm63xx/nvram.c |   23 +++++++++++++----------
19  1 files changed, 13 insertions(+), 10 deletions(-)
20
21 --- a/arch/mips/bcm63xx/nvram.c
22 +++ b/arch/mips/bcm63xx/nvram.c
23 @@ -11,6 +11,7 @@
24  #define pr_fmt(fmt) "bcm63xx_nvram: " fmt
25  
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)
33  {
34         unsigned int check_len;
35 -       u8 *p;
36 -       u32 val;
37 +       u32 crc, expected_crc;
38  
39         /* extract nvram data */
40         memcpy(&nvram, addr, sizeof(nvram));
41  
42         /* check checksum before using data */
43 -       if (nvram.version <= 4)
44 -               check_len = offsetof(struct bcm963xx_nvram, checksum_old);
45 -       else
46 +       if (nvram.version <= 4) {
47 +               check_len = offsetof(struct bcm963xx_nvram, reserved3);
48 +               expected_crc = nvram.checksum_old;
49 +               nvram.checksum_old = 0;
50 +       } else {
51                 check_len = sizeof(nvram);
52 -       val = 0;
53 -       p = (u8 *)&nvram;
54 +               expected_crc = nvram.checksum_high;
55 +               nvram.checksum_high = 0;
56 +       }
57  
58 -       while (check_len--)
59 -               val += *p;
60 -       if (val)
61 +       crc = crc32_le(~0, (u8 *)&nvram, check_len);
62 +
63 +       if (crc != expected_crc)
64                 return -EINVAL;
65  
66         return 0;