aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/vpd.c
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2021-08-18 20:59:31 +0200
committerBjorn Helgaas <bhelgaas@google.com>2021-08-20 15:13:20 -0500
commit76f3c032adad86aad26f8ad3eebc993b4ba32138 (patch)
treed4ad227a456d5233f998fb2435d94f35a215e0cc /drivers/pci/vpd.c
parentPCI/VPD: Treat invalid VPD like missing VPD capability (diff)
downloadlinux-dev-76f3c032adad86aad26f8ad3eebc993b4ba32138.tar.xz
linux-dev-76f3c032adad86aad26f8ad3eebc993b4ba32138.zip
PCI/VPD: Add pci_vpd_alloc()
Several users of the VPD API use a fixed-size buffer and read the VPD into it for further usage. This requires special handling for the case that the buffer isn't big enough to hold the full VPD data. Also the buffer is often allocated on the stack, which isn't too nice. Add pci_vpd_alloc() to dynamically allocate buffer of the correct size and read VPD into it. Link: https://lore.kernel.org/r/955ff598-0021-8446-f856-0c2c077635d7@gmail.com Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/vpd.c')
-rw-r--r--drivers/pci/vpd.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 3b0425fb49f5..7c3a097379bb 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -270,6 +270,32 @@ const struct attribute_group pci_dev_vpd_attr_group = {
.is_bin_visible = vpd_attr_is_visible,
};
+void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size)
+{
+ unsigned int len = dev->vpd.len;
+ void *buf;
+ int cnt;
+
+ if (!dev->vpd.cap)
+ return ERR_PTR(-ENODEV);
+
+ buf = kmalloc(len, GFP_KERNEL);
+ if (!buf)
+ return ERR_PTR(-ENOMEM);
+
+ cnt = pci_read_vpd(dev, 0, len, buf);
+ if (cnt != len) {
+ kfree(buf);
+ return ERR_PTR(-EIO);
+ }
+
+ if (size)
+ *size = len;
+
+ return buf;
+}
+EXPORT_SYMBOL_GPL(pci_vpd_alloc);
+
int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt)
{
int i = 0;