summaryrefslogtreecommitdiff
path: root/arch/mips/bcm63xx/nvram.c
diff options
context:
space:
mode:
authorJonas Gorski <jonas.gorski@gmail.com>2012-11-11 16:22:34 +0400
committerJohn Crispin <blogic@openwrt.org>2012-12-12 21:57:49 +0400
commitce8f0d0607bcad3ec0e8599be80353204427093e (patch)
tree9d5547b44b31086b498ac83045e3b3dc847836a2 /arch/mips/bcm63xx/nvram.c
parent2da4c74dc3711275e82856e62884c99f7a45f541 (diff)
downloadlinux-ce8f0d0607bcad3ec0e8599be80353204427093e.tar.xz
MIPS: BCM63XX: fix nvram checksum calculation
The current checksum calculation code does nothing except checking that the first byte of nvram is 0 without actually checking the checksum. Implement the correct checksum calculation by calculating the crc32 with the checksum field set to 0. Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com> Patchwork: http://patchwork.linux-mips.org/patch/4540
Diffstat (limited to 'arch/mips/bcm63xx/nvram.c')
-rw-r--r--arch/mips/bcm63xx/nvram.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/arch/mips/bcm63xx/nvram.c b/arch/mips/bcm63xx/nvram.c
index b57a10db7c98..620611680839 100644
--- a/arch/mips/bcm63xx/nvram.c
+++ b/arch/mips/bcm63xx/nvram.c
@@ -11,6 +11,7 @@
#define pr_fmt(fmt) "bcm63xx_nvram: " fmt
#include <linux/init.h>
+#include <linux/crc32.h>
#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/if_ether.h>
@@ -40,23 +41,25 @@ static int mac_addr_used;
int __init bcm63xx_nvram_init(void *addr)
{
unsigned int check_len;
- u8 *p;
- u32 val;
+ u32 crc, expected_crc;
/* extract nvram data */
memcpy(&nvram, addr, sizeof(nvram));
/* check checksum before using data */
- if (nvram.version <= 4)
- check_len = offsetof(struct bcm963xx_nvram, checksum_old);
- else
+ if (nvram.version <= 4) {
+ check_len = offsetof(struct bcm963xx_nvram, reserved3);
+ expected_crc = nvram.checksum_old;
+ nvram.checksum_old = 0;
+ } else {
check_len = sizeof(nvram);
- val = 0;
- p = (u8 *)&nvram;
+ expected_crc = nvram.checksum_high;
+ nvram.checksum_high = 0;
+ }
+
+ crc = crc32_le(~0, (u8 *)&nvram, check_len);
- while (check_len--)
- val += *p;
- if (val)
+ if (crc != expected_crc)
return -EINVAL;
return 0;