PCI: Allow access to VPD attributes with size 0
authorHannes Reinecke <[email protected]>
Mon, 15 Feb 2016 08:42:00 +0000 (09:42 +0100)
committerBjorn Helgaas <[email protected]>
Mon, 29 Feb 2016 23:46:50 +0000 (17:46 -0600)
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 <[email protected]>
Tested-by: Babu Moger <[email protected]>
Signed-off-by: Hannes Reinecke <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Cc: Alexander Duyck <[email protected]>
drivers/pci/pci-sysfs.c

index 95d9e7bd933bc880315d3584033c4ea2ca41a3b9..a730f54d12472876f58ba59b9a09014750dbe185 100644 (file)
@@ -769,10 +769,12 @@ static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj,
 {
        struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
 
-       if (off > bin_attr->size)
-               count = 0;
-       else if (count > bin_attr->size - off)
-               count = bin_attr->size - off;
+       if (bin_attr->size > 0) {
+               if (off > bin_attr->size)
+                       count = 0;
+               else if (count > bin_attr->size - off)
+                       count = bin_attr->size - off;
+       }
 
        return pci_read_vpd(dev, off, count, buf);
 }
@@ -783,10 +785,12 @@ static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj,
 {
        struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
 
-       if (off > bin_attr->size)
-               count = 0;
-       else if (count > bin_attr->size - off)
-               count = bin_attr->size - off;
+       if (bin_attr->size > 0) {
+               if (off > bin_attr->size)
+                       count = 0;
+               else if (count > bin_attr->size - off)
+                       count = bin_attr->size - off;
+       }
 
        return pci_write_vpd(dev, off, count, buf);
 }