Skip to content

Commit

Permalink
PCI/VPD: Remove struct pci_vpd.valid member
Browse files Browse the repository at this point in the history
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.com
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  • Loading branch information
Heiner Kallweit authored and Bjorn Helgaas committed Aug 12, 2021
1 parent a38fccd commit 22ff2bc
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions drivers/pci/vpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ struct pci_vpd {
struct mutex lock;
unsigned int len;
u8 cap;
unsigned int valid:1;
};

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));
}

#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
Expand All @@ -36,6 +36,9 @@ static size_t pci_vpd_size(struct pci_dev *dev)
size_t off = 0, size;
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) {
size = 0;

Expand All @@ -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) {
pci_warn(dev, "failed VPD read at offset %zu\n",
off + 1);
return off;
return off ?: PCI_VPD_SZ_INVALID;
}
size = pci_vpd_lrdt_size(header);
if (off + size > PCI_VPD_MAX_SIZE)
Expand All @@ -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",
header[0], size, off, off == 0 ?
"; assume missing optional EEPROM" : "");
return off;
return off ?: PCI_VPD_SZ_INVALID;
}

/*
Expand Down Expand Up @@ -127,12 +130,10 @@ static ssize_t pci_vpd_read(struct pci_dev *dev, loff_t pos, size_t count,
if (pos < 0)
return -EINVAL;

if (!vpd->valid) {
vpd->valid = 1;
if (!vpd->len)
vpd->len = pci_vpd_size(dev);
}

if (vpd->len == 0)
if (vpd->len == PCI_VPD_SZ_INVALID)
return -EIO;

if (pos > vpd->len)
Expand Down Expand Up @@ -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))
return -EINVAL;

if (!vpd->valid) {
vpd->valid = 1;
if (!vpd->len)
vpd->len = pci_vpd_size(dev);
}

if (vpd->len == 0)
if (vpd->len == PCI_VPD_SZ_INVALID)
return -EIO;

if (end > vpd->len)
Expand Down Expand Up @@ -250,10 +249,8 @@ void pci_vpd_init(struct pci_dev *dev)
if (!vpd)
return;

vpd->len = PCI_VPD_MAX_SIZE;
mutex_init(&vpd->lock);
vpd->cap = cap;
vpd->valid = 0;
dev->vpd = vpd;
}

Expand Down Expand Up @@ -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)
{
if (dev->vpd) {
dev->vpd->len = 0;
dev->vpd->valid = 1;
dev->vpd->len = PCI_VPD_SZ_INVALID;
pci_warn(dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n");
}
}
Expand Down Expand Up @@ -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)
return;

vpd->valid = 1;
vpd->len = len;
}

Expand Down

0 comments on commit 22ff2bc

Please sign in to comment.