Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tg3: Read VPD with pci_vpd_alloc()

Use pci_vpd_alloc() to dynamically allocate a properly sized buffer and
read the full VPD data into it.

This simplifies the code, and we no longer have to make assumptions about
VPD size.

Link: https://lore.kernel.org/r/bd3cd19c-b74f-9704-5786-476bf35ab5de@gmail.com
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

authored by

Heiner Kallweit and committed by
Bjorn Helgaas
f240e150 37838aa4

+10 -18
+10 -17
drivers/net/ethernet/broadcom/tg3.c
··· 12791 12791 memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); 12792 12792 } 12793 12793 12794 - static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) 12794 + static __be32 *tg3_vpd_readblock(struct tg3 *tp, unsigned int *vpdlen) 12795 12795 { 12796 12796 int i; 12797 12797 __be32 *buf; ··· 12825 12825 offset = TG3_NVM_VPD_OFF; 12826 12826 len = TG3_NVM_VPD_LEN; 12827 12827 } 12828 - } else { 12829 - len = TG3_NVM_PCI_VPD_MAX_LEN; 12830 - } 12831 12828 12832 - buf = kmalloc(len, GFP_KERNEL); 12833 - if (buf == NULL) 12834 - return NULL; 12829 + buf = kmalloc(len, GFP_KERNEL); 12830 + if (!buf) 12831 + return NULL; 12835 12832 12836 - if (magic == TG3_EEPROM_MAGIC) { 12837 12833 for (i = 0; i < len; i += 4) { 12838 12834 /* The data is in little-endian format in NVRAM. 12839 12835 * Use the big-endian read routines to preserve ··· 12840 12844 } 12841 12845 *vpdlen = len; 12842 12846 } else { 12843 - ssize_t cnt; 12844 - 12845 - cnt = pci_read_vpd(tp->pdev, 0, len, (u8 *)buf); 12846 - if (cnt < 0) 12847 - goto error; 12848 - *vpdlen = cnt; 12847 + buf = pci_vpd_alloc(tp->pdev, vpdlen); 12848 + if (IS_ERR(buf)) 12849 + return NULL; 12849 12850 } 12850 12851 12851 12852 return buf; ··· 12864 12871 12865 12872 static int tg3_test_nvram(struct tg3 *tp) 12866 12873 { 12867 - u32 csum, magic, len; 12874 + u32 csum, magic; 12868 12875 __be32 *buf; 12869 12876 int i, j, k, err = 0, size; 12877 + unsigned int len; 12870 12878 12871 12879 if (tg3_flag(tp, NO_NVRAM)) 12872 12880 return 0; ··· 15615 15621 static void tg3_read_vpd(struct tg3 *tp) 15616 15622 { 15617 15623 u8 *vpd_data; 15618 - unsigned int block_end, rosize, len; 15619 - u32 vpdlen; 15624 + unsigned int block_end, rosize, len, vpdlen; 15620 15625 int j, i = 0; 15621 15626 15622 15627 vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen);
-1
drivers/net/ethernet/broadcom/tg3.h
··· 2101 2101 /* Hardware Legacy NVRAM layout */ 2102 2102 #define TG3_NVM_VPD_OFF 0x100 2103 2103 #define TG3_NVM_VPD_LEN 256 2104 - #define TG3_NVM_PCI_VPD_MAX_LEN 512 2105 2104 2106 2105 /* Hardware Selfboot NVRAM layout */ 2107 2106 #define TG3_NVM_HWSB_CFG1 0x00000004