diff mbox series

[5/5] PCI/VPD: Allow access to valid parts of VPD if some is invalid

Message ID 20210715215959.2014576-6-helgaas@kernel.org (mailing list archive)
State Superseded
Delegated to: Bjorn Helgaas
Headers show
Series PCI/VPD: pci_vpd_size() cleanups | expand

Commit Message

Bjorn Helgaas July 15, 2021, 9:59 p.m. UTC
From: Bjorn Helgaas <bhelgaas@google.com>

Previously, if we found any error in the VPD, we returned size 0, which
prevents access to all of VPD.  But there may be valid resources in VPD
before the error, and there's no reason to prevent access to those.

"off" covers only VPD resources known to have valid header tags.  In case
of error, return "off" (which may be zero if we haven't found any valid
header tags at all).

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/vpd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Hannes Reinecke July 16, 2021, 6:04 a.m. UTC | #1
On 7/15/21 11:59 PM, Bjorn Helgaas wrote:
> From: Bjorn Helgaas <bhelgaas@google.com>
> 
> Previously, if we found any error in the VPD, we returned size 0, which
> prevents access to all of VPD.  But there may be valid resources in VPD
> before the error, and there's no reason to prevent access to those.
> 
> "off" covers only VPD resources known to have valid header tags.  In case
> of error, return "off" (which may be zero if we haven't found any valid
> header tags at all).
> 
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> ---
>   drivers/pci/vpd.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
D'oh. Of course.

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
diff mbox series

Patch

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index d7a4a9f05bd6..92acbbcc8059 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -85,7 +85,7 @@  static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size)
 			if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) {
 				pci_warn(dev, "failed VPD read at offset %zu",
 					 off + 1);
-				return 0;
+				return off;
 			}
 			size = pci_vpd_lrdt_size(header);
 
@@ -115,13 +115,13 @@  static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size)
 				return off;
 		}
 	}
-	return 0;
+	return off;
 
 error:
 	pci_info(dev, "invalid VPD tag %#04x at offset %zu%s\n",
 		 header[0], off, off == 0 ?
 		 "; assume missing optional EEPROM" : "");
-	return 0;
+	return off;
 }
 
 /*