[PATCH] pciutils: Fix sysfs_get_string to handle invalid read

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 - Fix minor indentation alignment

Signed-off-by: Ameya Palande <2ameya@xxxxxxxxx>
---
 lib/sysfs.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lib/sysfs.c b/lib/sysfs.c
index 9f348bb..90ed013 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -99,15 +99,21 @@ sysfs_get_string(struct pci_dev *d, char *object, char *buf, int mandatory)
   if (fd < 0)
     {
       if (mandatory)
-	a->error("Cannot open %s: %s", namebuf, strerror(errno));
+        a->error("Cannot open %s: %s", namebuf, strerror(errno));
       return 0;
     }
   n = read(fd, buf, OBJBUFSIZE);
   close(fd);
-  if (n < 0)
-    a->error("Error reading %s: %s", namebuf, strerror(errno));
-  if (n >= OBJBUFSIZE)
-    a->error("Value in %s too long", namebuf);
+  if (n < 0) {
+    if (mandatory)
+      a->error("Error reading %s: %s", namebuf, strerror(errno));
+    return 0;
+  }
+  if (n >= OBJBUFSIZE) {
+    if (mandatory)
+      a->error("Value in %s too long", namebuf);
+    return 0;
+  }
   buf[n] = 0;
   return 1;
 }
@@ -274,21 +280,21 @@ sysfs_fill_info(struct pci_dev *d, int flags)
       struct pci_dev *pd;
       sysfs_fill_slots(d->access);
       for (pd = d->access->devices; pd; pd = pd->next)
-	pd->known_fields |= PCI_FILL_PHYS_SLOT;
+        pd->known_fields |= PCI_FILL_PHYS_SLOT;
     }
 
   if ((flags & PCI_FILL_MODULE_ALIAS) && !(d->known_fields & PCI_FILL_MODULE_ALIAS))
     {
       char buf[OBJBUFSIZE];
       if (sysfs_get_string(d, "modalias", buf, 0))
-	d->module_alias = pci_strdup(d->access, buf);
+        d->module_alias = pci_strdup(d->access, buf);
     }
 
   if ((flags & PCI_FILL_LABEL) && !(d->known_fields & PCI_FILL_LABEL))
     {
       char buf[OBJBUFSIZE];
       if (sysfs_get_string(d, "label", buf, 0))
-	d->label = pci_strdup(d->access, buf);
+        d->label = pci_strdup(d->access, buf);
     }
 
   return pci_generic_fill_info(d, flags);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux