Commit 535a490e authored by Matt Carlson's avatar Matt Carlson Committed by David S. Miller

tg3: Return size from tg3_vpd_readblock()

Newer VPD datablocks can exceed the size the tg3 driver is traditionally
used to.  This can cause some of the routines that operate on the VPD
data to fail when in-fact they could have succeeded had they known the
correct size.  This patch fixes the problem.
Signed-off-by: default avatarMatt Carlson <mcarlson@broadcom.com>
Reviewed-by: default avatarMichael Chan <mchan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3aa1cdf8
...@@ -10573,7 +10573,7 @@ static void tg3_get_ethtool_stats(struct net_device *dev, ...@@ -10573,7 +10573,7 @@ static void tg3_get_ethtool_stats(struct net_device *dev,
memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats));
} }
static __be32 * tg3_vpd_readblock(struct tg3 *tp) static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen)
{ {
int i; int i;
__be32 *buf; __be32 *buf;
...@@ -10640,6 +10640,8 @@ static __be32 * tg3_vpd_readblock(struct tg3 *tp) ...@@ -10640,6 +10640,8 @@ static __be32 * tg3_vpd_readblock(struct tg3 *tp)
goto error; goto error;
} }
*vpdlen = len;
return buf; return buf;
error: error:
...@@ -10659,7 +10661,7 @@ static __be32 * tg3_vpd_readblock(struct tg3 *tp) ...@@ -10659,7 +10661,7 @@ static __be32 * tg3_vpd_readblock(struct tg3 *tp)
static int tg3_test_nvram(struct tg3 *tp) static int tg3_test_nvram(struct tg3 *tp)
{ {
u32 csum, magic; u32 csum, magic, len;
__be32 *buf; __be32 *buf;
int i, j, k, err = 0, size; int i, j, k, err = 0, size;
...@@ -10800,18 +10802,17 @@ static int tg3_test_nvram(struct tg3 *tp) ...@@ -10800,18 +10802,17 @@ static int tg3_test_nvram(struct tg3 *tp)
kfree(buf); kfree(buf);
buf = tg3_vpd_readblock(tp); buf = tg3_vpd_readblock(tp, &len);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
i = pci_vpd_find_tag((u8 *)buf, 0, TG3_NVM_VPD_LEN, i = pci_vpd_find_tag((u8 *)buf, 0, len, PCI_VPD_LRDT_RO_DATA);
PCI_VPD_LRDT_RO_DATA);
if (i > 0) { if (i > 0) {
j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); j = pci_vpd_lrdt_size(&((u8 *)buf)[i]);
if (j < 0) if (j < 0)
goto out; goto out;
if (i + PCI_VPD_LRDT_TAG_SIZE + j > TG3_NVM_VPD_LEN) if (i + PCI_VPD_LRDT_TAG_SIZE + j > len)
goto out; goto out;
i += PCI_VPD_LRDT_TAG_SIZE; i += PCI_VPD_LRDT_TAG_SIZE;
...@@ -13209,14 +13210,14 @@ static void __devinit tg3_read_vpd(struct tg3 *tp) ...@@ -13209,14 +13210,14 @@ static void __devinit tg3_read_vpd(struct tg3 *tp)
{ {
u8 *vpd_data; u8 *vpd_data;
unsigned int block_end, rosize, len; unsigned int block_end, rosize, len;
u32 vpdlen;
int j, i = 0; int j, i = 0;
vpd_data = (u8 *)tg3_vpd_readblock(tp); vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen);
if (!vpd_data) if (!vpd_data)
goto out_no_vpd; goto out_no_vpd;
i = pci_vpd_find_tag(vpd_data, 0, TG3_NVM_VPD_LEN, i = pci_vpd_find_tag(vpd_data, 0, vpdlen, PCI_VPD_LRDT_RO_DATA);
PCI_VPD_LRDT_RO_DATA);
if (i < 0) if (i < 0)
goto out_not_found; goto out_not_found;
...@@ -13224,7 +13225,7 @@ static void __devinit tg3_read_vpd(struct tg3 *tp) ...@@ -13224,7 +13225,7 @@ static void __devinit tg3_read_vpd(struct tg3 *tp)
block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize;
i += PCI_VPD_LRDT_TAG_SIZE; i += PCI_VPD_LRDT_TAG_SIZE;
if (block_end > TG3_NVM_VPD_LEN) if (block_end > vpdlen)
goto out_not_found; goto out_not_found;
j = pci_vpd_find_info_keyword(vpd_data, i, rosize, j = pci_vpd_find_info_keyword(vpd_data, i, rosize,
...@@ -13249,7 +13250,7 @@ static void __devinit tg3_read_vpd(struct tg3 *tp) ...@@ -13249,7 +13250,7 @@ static void __devinit tg3_read_vpd(struct tg3 *tp)
goto partno; goto partno;
memcpy(tp->fw_ver, &vpd_data[j], len); memcpy(tp->fw_ver, &vpd_data[j], len);
strncat(tp->fw_ver, " bc ", TG3_NVM_VPD_LEN - len - 1); strncat(tp->fw_ver, " bc ", vpdlen - len - 1);
} }
partno: partno:
...@@ -13262,7 +13263,7 @@ static void __devinit tg3_read_vpd(struct tg3 *tp) ...@@ -13262,7 +13263,7 @@ static void __devinit tg3_read_vpd(struct tg3 *tp)
i += PCI_VPD_INFO_FLD_HDR_SIZE; i += PCI_VPD_INFO_FLD_HDR_SIZE;
if (len > TG3_BPN_SIZE || if (len > TG3_BPN_SIZE ||
(len + i) > TG3_NVM_VPD_LEN) (len + i) > vpdlen)
goto out_not_found; goto out_not_found;
memcpy(tp->board_part_number, &vpd_data[i], len); memcpy(tp->board_part_number, &vpd_data[i], len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment