提交 ce8f0d06 编写于 作者: J Jonas Gorski 提交者: John Crispin

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: NJonas Gorski <jonas.gorski@gmail.com>
Patchwork: http://patchwork.linux-mips.org/patch/4540
上级 2da4c74d
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define pr_fmt(fmt) "bcm63xx_nvram: " fmt #define pr_fmt(fmt) "bcm63xx_nvram: " fmt
#include <linux/init.h> #include <linux/init.h>
#include <linux/crc32.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
...@@ -40,23 +41,25 @@ static int mac_addr_used; ...@@ -40,23 +41,25 @@ static int mac_addr_used;
int __init bcm63xx_nvram_init(void *addr) int __init bcm63xx_nvram_init(void *addr)
{ {
unsigned int check_len; unsigned int check_len;
u8 *p; u32 crc, expected_crc;
u32 val;
/* extract nvram data */ /* extract nvram data */
memcpy(&nvram, addr, sizeof(nvram)); memcpy(&nvram, addr, sizeof(nvram));
/* check checksum before using data */ /* check checksum before using data */
if (nvram.version <= 4) if (nvram.version <= 4) {
check_len = offsetof(struct bcm963xx_nvram, checksum_old); check_len = offsetof(struct bcm963xx_nvram, reserved3);
else expected_crc = nvram.checksum_old;
nvram.checksum_old = 0;
} else {
check_len = sizeof(nvram); check_len = sizeof(nvram);
val = 0; expected_crc = nvram.checksum_high;
p = (u8 *)&nvram; nvram.checksum_high = 0;
}
crc = crc32_le(~0, (u8 *)&nvram, check_len);
while (check_len--) if (crc != expected_crc)
val += *p;
if (val)
return -EINVAL; return -EINVAL;
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册