Skip to content

Commit f52e562

Browse files
hreineckebjorn-helgaas
authored andcommitted
PCI: Allow access to VPD attributes with size 0
It is not always possible to determine the actual size of the VPD data, so allow access to them if the size is set to '0'. Tested-by: Shane Seymour <shane.seymour@hpe.com> Tested-by: Babu Moger <babu.moger@oracle.com> Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Alexander Duyck <alexander.duyck@gmail.com>
1 parent 9eb45d5 commit f52e562

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,12 @@ static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj,
769769
{
770770
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
771771

772-
if (off > bin_attr->size)
773-
count = 0;
774-
else if (count > bin_attr->size - off)
775-
count = bin_attr->size - off;
772+
if (bin_attr->size > 0) {
773+
if (off > bin_attr->size)
774+
count = 0;
775+
else if (count > bin_attr->size - off)
776+
count = bin_attr->size - off;
777+
}
776778

777779
return pci_read_vpd(dev, off, count, buf);
778780
}
@@ -783,10 +785,12 @@ static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj,
783785
{
784786
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
785787

786-
if (off > bin_attr->size)
787-
count = 0;
788-
else if (count > bin_attr->size - off)
789-
count = bin_attr->size - off;
788+
if (bin_attr->size > 0) {
789+
if (off > bin_attr->size)
790+
count = 0;
791+
else if (count > bin_attr->size - off)
792+
count = bin_attr->size - off;
793+
}
790794

791795
return pci_write_vpd(dev, off, count, buf);
792796
}

0 commit comments

Comments
 (0)