diff mbox

pciutils: Fix sysfs_get_string to handle invalid read

Message ID 1440444745-7560-1-git-send-email-2ameya@gmail.com
State Not Applicable
Headers show

Commit Message

Ameya Palande Aug. 24, 2015, 7:32 p.m. UTC
- Fix minor indentation alignment

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

Comments

Martin Mareš Aug. 24, 2015, 8:08 p.m. UTC | #1
Hello!

>  - Fix minor indentation alignment

I am not sure what you intend to do. Your indentation fixes do not
seem to fix anything -- maybe you have a non-standard tab size?

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

Patch

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);