| To: | linux-mips@linux-mips.org |
|---|---|
| Subject: | [PATCH] MIPS: BCM63XX: fix nvram checksum calculation |
| From: | Jonas Gorski <jonas.gorski@gmail.com> |
| Date: | Sun, 11 Nov 2012 14:22:34 +0100 |
| Cc: | Ralf Baechle <ralf@linux-mips.org>, John Crispin <blogic@openwrt.org>, Maxime Bizon <mbizon@freebox.fr>, Florian Fainelli <florian@openwrt.org>, Kevin Cernekee <cernekee@gmail.com> |
| Dkim-signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=QmNQL2q+PxhmROOPNot6D8+3obmeyjc1CUXusc8eybg=; b=zv3qaijy4s2iuFfuA1DJFgh746Fsrf0xeQFmfZljo2h46ix/mZznCqwlA7zQoMFho6 bu8Dtl+XBjt1GWwYpWh1f844u8sC8Ll47xTmdIVcXOABr3VHF5bNLc/orLLkySesLf39 Zs8HWZdDh0ge+7K+K+mucRMesift7yBEZrhQhPXgfks5vT0TxiD4zs2nwNSVR9gjG944 Tlgg/VzGP6wHnJMLerpXIy2IpOpG6wWEgPQwMbWAzDc1xSwS42raJiIz9wddjktH+DvC UMgzB5wxgE4skmfYl3UTlnZWPLVWmwuiAf/aq/OtGhe155Y3dYyti5k1IjYX81bXH/Le SrBA== |
| List-archive: | <http://www.linux-mips.org/archives/linux-mips/> |
| List-help: | <mailto:ecartis@linux-mips.org?Subject=help> |
| List-id: | linux-mips <linux-mips.eddie.linux-mips.org> |
| List-owner: | <mailto:ralf@linux-mips.org> |
| List-post: | <mailto:linux-mips@linux-mips.org> |
| List-software: | Ecartis version 1.0.0 |
| List-subscribe: | <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips> |
| List-unsubscribe: | <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips> |
| Sender: | linux-mips-bounce@linux-mips.org |
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>
---
This patch depends on the previous nvram patch ("move nvram functions
into their own file").
arch/mips/bcm63xx/nvram.c | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/arch/mips/bcm63xx/nvram.c b/arch/mips/bcm63xx/nvram.c
index b57a10d..6206116 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;
--
1.7.2.5
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: [RFC] MIPS: BCM63XX: add initial Device Tree support, Jonas Gorski |
|---|---|
| Next by Date: | [MIPS] Pull request for 3.8, John Crispin |
| Previous by Thread: | [RFC] MIPS: BCM63XX: add initial Device Tree support, Jonas Gorski |
| Next by Thread: | [MIPS] Pull request for 3.8, John Crispin |
| Indexes: | [Date] [Thread] [Top] [All Lists] |