Commit 22ff2bce authored by Heiner Kallweit's avatar Heiner Kallweit Committed by Bjorn Helgaas

PCI/VPD: Remove struct pci_vpd.valid member

Instead of having a separate flag, use vp->len != 0 as indicator that VPD
validity has been checked.  Now vpd->len == PCI_VPD_SZ_INVALID indicates
that VPD is invalid.

Link: https://lore.kernel.org/r/9f777bc7-5316-e1b8-e5d4-f9f609bdb5dd@gmail.comSigned-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent a38fccdb
...@@ -17,7 +17,6 @@ struct pci_vpd { ...@@ -17,7 +17,6 @@ struct pci_vpd {
struct mutex lock; struct mutex lock;
unsigned int len; unsigned int len;
u8 cap; u8 cap;
unsigned int valid:1;
}; };
static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev) static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev)
...@@ -25,7 +24,8 @@ static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev) ...@@ -25,7 +24,8 @@ static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev)
return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
} }
#define PCI_VPD_MAX_SIZE (PCI_VPD_ADDR_MASK + 1) #define PCI_VPD_MAX_SIZE (PCI_VPD_ADDR_MASK + 1)
#define PCI_VPD_SZ_INVALID UINT_MAX
/** /**
* pci_vpd_size - determine actual size of Vital Product Data * pci_vpd_size - determine actual size of Vital Product Data
...@@ -36,6 +36,9 @@ static size_t pci_vpd_size(struct pci_dev *dev) ...@@ -36,6 +36,9 @@ static size_t pci_vpd_size(struct pci_dev *dev)
size_t off = 0, size; size_t off = 0, size;
unsigned char tag, header[1+2]; /* 1 byte tag, 2 bytes length */ unsigned char tag, header[1+2]; /* 1 byte tag, 2 bytes length */
/* Otherwise the following reads would fail. */
dev->vpd->len = PCI_VPD_MAX_SIZE;
while (pci_read_vpd(dev, off, 1, header) == 1) { while (pci_read_vpd(dev, off, 1, header) == 1) {
size = 0; size = 0;
...@@ -47,7 +50,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) ...@@ -47,7 +50,7 @@ static size_t pci_vpd_size(struct pci_dev *dev)
if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) { if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) {
pci_warn(dev, "failed VPD read at offset %zu\n", pci_warn(dev, "failed VPD read at offset %zu\n",
off + 1); off + 1);
return off; return off ?: PCI_VPD_SZ_INVALID;
} }
size = pci_vpd_lrdt_size(header); size = pci_vpd_lrdt_size(header);
if (off + size > PCI_VPD_MAX_SIZE) if (off + size > PCI_VPD_MAX_SIZE)
...@@ -72,7 +75,7 @@ static size_t pci_vpd_size(struct pci_dev *dev) ...@@ -72,7 +75,7 @@ static size_t pci_vpd_size(struct pci_dev *dev)
pci_info(dev, "invalid VPD tag %#04x (size %zu) at offset %zu%s\n", pci_info(dev, "invalid VPD tag %#04x (size %zu) at offset %zu%s\n",
header[0], size, off, off == 0 ? header[0], size, off, off == 0 ?
"; assume missing optional EEPROM" : ""); "; assume missing optional EEPROM" : "");
return off; return off ?: PCI_VPD_SZ_INVALID;
} }
/* /*
...@@ -127,12 +130,10 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count, ...@@ -127,12 +130,10 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
if (pos < 0) if (pos < 0)
return -EINVAL; return -EINVAL;
if (!vpd->valid) { if (!vpd->len)
vpd->valid = 1;
vpd->len = pci_vpd_size(dev); vpd->len = pci_vpd_size(dev);
}
if (vpd->len == 0) if (vpd->len == PCI_VPD_SZ_INVALID)
return -EIO; return -EIO;
if (pos > vpd->len) if (pos > vpd->len)
...@@ -196,12 +197,10 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count, ...@@ -196,12 +197,10 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
if (pos < 0 || (pos & 3) || (count & 3)) if (pos < 0 || (pos & 3) || (count & 3))
return -EINVAL; return -EINVAL;
if (!vpd->valid) { if (!vpd->len)
vpd->valid = 1;
vpd->len = pci_vpd_size(dev); vpd->len = pci_vpd_size(dev);
}
if (vpd->len == 0) if (vpd->len == PCI_VPD_SZ_INVALID)
return -EIO; return -EIO;
if (end > vpd->len) if (end > vpd->len)
...@@ -250,10 +249,8 @@ void pci_vpd_init(struct pci_dev *dev) ...@@ -250,10 +249,8 @@ void pci_vpd_init(struct pci_dev *dev)
if (!vpd) if (!vpd)
return; return;
vpd->len = PCI_VPD_MAX_SIZE;
mutex_init(&vpd->lock); mutex_init(&vpd->lock);
vpd->cap = cap; vpd->cap = cap;
vpd->valid = 0;
dev->vpd = vpd; dev->vpd = vpd;
} }
...@@ -422,8 +419,7 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, ...@@ -422,8 +419,7 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
static void quirk_blacklist_vpd(struct pci_dev *dev) static void quirk_blacklist_vpd(struct pci_dev *dev)
{ {
if (dev->vpd) { if (dev->vpd) {
dev->vpd->len = 0; dev->vpd->len = PCI_VPD_SZ_INVALID;
dev->vpd->valid = 1;
pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n"); pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n");
} }
} }
...@@ -454,7 +450,6 @@ static void pci_vpd_set_size(struct pci_dev *dev, size_t len) ...@@ -454,7 +450,6 @@ static void pci_vpd_set_size(struct pci_dev *dev, size_t len)
if (!vpd || len == 0 || len > PCI_VPD_MAX_SIZE) if (!vpd || len == 0 || len > PCI_VPD_MAX_SIZE)
return; return;
vpd->valid = 1;
vpd->len = len; vpd->len = 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