[PATCH libdrm 02/12] xf86drm: flex platform specifics into drmParsePciBusInfo

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

 



This will allow one to reuse the core drmGetDevices implementation on
other platforms. Keeping all the platform specifics in ParseFoo.

On the plus side this saves a bit of code :)

Signed-off-by: Emil Velikov <emil.l.velikov@xxxxxxxxx>
---
 xf86drm.c | 46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index a5a7b41..b4c5aa0 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2855,23 +2855,33 @@ static int drmParseSubsystemType(const char *str)
     return -EINVAL;
 }
 
-static int drmParsePciBusInfo(const char *str, drmPciBusInfoPtr info)
+static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
 {
+    char path[PATH_MAX + 1];
+    char data[128];
+    char *str;
     int domain, bus, dev, func;
-    char *value;
+    int fd, ret;
 
-    if (str == NULL)
-        return -EINVAL;
+    snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/uevent", maj, min);
+    fd = open(path, O_RDONLY);
+    if (fd < 0)
+        return -errno;
 
-    value = strstr(str, "PCI_SLOT_NAME=");
-    if (value == NULL)
-        return -EINVAL;
+    ret = read(fd, data, sizeof(data));
+    close(fd);
+    if (ret < 0)
+        return -errno;
 
-    value += strlen("PCI_SLOT_NAME=");
+#define TAG "PCI_SLOT_NAME="
+    str = strstr(data, TAG);
+    if (str == NULL)
+        return -EINVAL;
 
-    if (sscanf(value, "%04x:%02x:%02x.%1u",
+    if (sscanf(str, TAG "%04x:%02x:%02x.%1u",
                &domain, &bus, &dev, &func) != 4)
         return -EINVAL;
+#undef TAG
 
     info->domain = domain;
     info->bus = bus;
@@ -2981,7 +2991,6 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
     struct stat sbuf = {0};
     char node[PATH_MAX + 1] = "";
     char path[PATH_MAX + 1] = "";
-    char data[128] = "";
     unsigned char config[64] = "";
     int node_type, subsystem_type;
     int maj, min;
@@ -3030,22 +3039,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
                 goto free_locals;
             }
 
-            snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/uevent",
-                     maj, min);
-            fd = open(path, O_RDONLY);
-            if (fd < 0) {
-                ret = -errno;
-                goto free_locals;
-            }
-            ret = read(fd, data, sizeof(data));
-            if (ret < 0) {
-                ret = -errno;
-                close(fd);
-                goto free_locals;
-            }
-
-            ret = drmParsePciBusInfo(data, pcibus);
-            close(fd);
+            ret = drmParsePciBusInfo(maj, min, pcibus);
             if (ret)
                 goto free_locals;
 
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux