diff mbox series

[pciutils,3/4] libpci: sysfs: Implement support for PCI_FILL_DRIVER

Message ID 20220121140351.27382-4-pali@kernel.org
State New
Headers show
Series Support for PCI_FILL_DRIVER | expand

Commit Message

Pali Rohár Jan. 21, 2022, 2:03 p.m. UTC
In sysfs is driver name stored as symlink path of "driver" node.
---
 lib/sysfs.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/lib/sysfs.c b/lib/sysfs.c
index 7714607f66a0..0dbd127ff53b 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -445,6 +445,19 @@  sysfs_fill_info(struct pci_dev *d, unsigned int flags)
       done |= PCI_FILL_DT_NODE;
     }
 
+  if (flags & PCI_FILL_DRIVER)
+    {
+      char *driver_path = sysfs_deref_link(d, "driver");
+      if (driver_path)
+        {
+          char *driver = strrchr(driver_path, '/');
+          driver = driver ? driver+1 : driver_path;
+          pci_set_property(d, PCI_FILL_DRIVER, driver);
+          free(driver_path);
+        }
+      done |= PCI_FILL_DRIVER;
+    }
+
   return done | pci_generic_fill_info(d, flags & ~done);
 }