From e5bb788bdd5c328e11f9450089710857e93362ae Mon Sep 17 00:00:00 2001 From: Hayes Wang Date: Sat, 18 Jun 2011 11:37:48 +0200 Subject: [PATCH] --- yaml --- r: 255591 b: refs/heads/master c: 960aee6c7d5951ac20c0227ad73bad56392f0afc h: refs/heads/master i: 255589: 5a25aef47dedcb44b40fa05eebf54fd76d869028 255587: 89690906da9bea5034c301442fa738cd761e9c2c 255583: 1f4a29d4e191b6d7b134fa15d46a18e24cf20a0e v: v3 --- [refs] | 2 +- trunk/drivers/net/r8169.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 599870e36cc7..54c332a3ca93 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 1c361efb226d609a07403057a71557faf500b17a +refs/heads/master: 960aee6c7d5951ac20c0227ad73bad56392f0afc diff --git a/trunk/drivers/net/r8169.c b/trunk/drivers/net/r8169.c index 8fc9af246944..7074989d5f75 100644 --- a/trunk/drivers/net/r8169.c +++ b/trunk/drivers/net/r8169.c @@ -1754,18 +1754,52 @@ static void rtl_writephy_batch(struct rtl8169_private *tp, #define PHY_DELAY_MS 0xe0000000 #define PHY_WRITE_ERI_WORD 0xf0000000 +struct fw_info { + u32 magic; + char version[RTL_VER_SIZE]; + __le32 fw_start; + __le32 fw_len; + u8 chksum; +} __packed; + #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) static bool rtl_fw_format_ok(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) { const struct firmware *fw = rtl_fw->fw; + struct fw_info *fw_info = (struct fw_info *)fw->data; struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; char *version = rtl_fw->version; bool rc = false; if (fw->size < FW_OPCODE_SIZE) goto out; - else { + + if (!fw_info->magic) { + size_t i, size, start; + u8 checksum = 0; + + if (fw->size < sizeof(*fw_info)) + goto out; + + for (i = 0; i < fw->size; i++) + checksum += fw->data[i]; + if (checksum != 0) + goto out; + + start = le32_to_cpu(fw_info->fw_start); + if (start > fw->size) + goto out; + + size = le32_to_cpu(fw_info->fw_len); + if (size > (fw->size - start) / FW_OPCODE_SIZE) + goto out; + + memcpy(version, fw_info->version, RTL_VER_SIZE); + + pa->code = (__le32 *)(fw->data + start); + pa->size = size; + } else { if (fw->size % FW_OPCODE_SIZE) goto out;