[systemd-devel] [PATCH] udev: make net_id more robust

Sean McGovern gseanmcg at gmail.com
Fri Jun 7 06:27:26 PDT 2013


Onboard network controllers are not always on PCI domain 0.
---
 src/udev/udev-builtin-net_id.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 5719021..3e77f30 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -163,6 +163,7 @@ out:
 
 static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
         struct udev *udev = udev_device_get_udev(names->pcidev);
+        unsigned long domain __attribute__((__unused__));
         unsigned int bus;
         unsigned int slot;
         unsigned int func;
@@ -171,6 +172,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
         char *s;
         const char *attr;
         struct udev_device *pci = NULL;
+        char *sysname;
         char slots[256];
         DIR *dir;
         struct dirent *dent;
@@ -178,8 +180,16 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
         int hotplug_slot = 0;
         int err = 0;
 
-        if (sscanf(udev_device_get_sysname(names->pcidev), "0000:%x:%x.%d", &bus, &slot, &func) != 3)
-                return -ENOENT;
+        sysname = udev_device_get_sysname(names->pcidev);
+
+        if(!sysname)
+            return -ENOENT;
+
+        if(!strlen(sysname))
+            return -ENOENT;
+
+        if(sscanf(sysname, "%lx:%x:%x.%d", &domain, &bus, &slot, &func) != 4)
+            return -ENOENT;
 
         /* kernel provided multi-device index */
         attr = udev_device_get_sysattr_value(dev, "dev_id");
-- 
1.8.2.1



More information about the systemd-devel mailing list