Skip to content

Commit

Permalink
MIPS: BCM63XX: fix nvram checksum calculation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jonas Gorski authored and John Crispin committed Dec 12, 2012
1 parent 2da4c74 commit ce8f0d0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions arch/mips/bcm63xx/nvram.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ce8f0d0

Please sign in to comment.