Skip to contentSkip to conversation

xf86drm: merge get_normal_pci_path() into get_real_pci_path()

PATCH In review Eric Engestrom 2 participants 3 messages Sep 5, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xf86drm: merge get_normal_pci_path() into get_real_pci_path()

---
 xf86drm.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)
xf86drm.c +8 -17
index 7807dce9c7fbba6d74f7..649d400bcbc494ac04e6 100644
@@ -2998,26 +2998,20 @@ static int drmParseSubsystemType(int maj, int min)
 #endif
 }
 
-static char *
+static void
 get_real_pci_path(int maj, int min, char *real_path)
 {
     char path[PATH_MAX + 1], *term;
 
     snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
-    if (!realpath(path, real_path))
-        return NULL;
+    if (!realpath(path, real_path)) {
+        strcpy(real_path, path);
+        return;
+    }
 
     term = strrchr(real_path, '/');
     if (term && strncmp(term, "/virtio", 7) == 0)
         *term = 0;
-
-    return real_path;
-}
-
-static void
-get_normal_pci_path(int maj, int min, char *normal_path)
-{
-    snprintf(normal_path, PATH_MAX, "/sys/dev/char/%d:%d/device", maj, min);
 }
 
 static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
@@ -3027,8 +3021,7 @@ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
     char real_path[PATH_MAX + 1], *value;
     int num;
 
-    if (get_real_pci_path(maj, min, real_path) == NULL)
-        get_normal_pci_path(maj, min, real_path);
+    get_real_pci_path(maj, min, real_path);
 
     value = sysfs_uevent_get(real_path, "PCI_SLOT_NAME");
     if (!value)
@@ -3148,8 +3141,7 @@ static int parse_separate_sysfs_files(int maj, int min,
     FILE *fp;
     int ret;
 
-    if (get_real_pci_path(maj, min, real_path) == NULL)
-        get_normal_pci_path(maj, min, real_path);
+    get_real_pci_path(maj, min, real_path);
 
     for (unsigned i = ignore_revision ? 1 : 0; i < ARRAY_SIZE(attrs); i++) {
         snprintf(path, PATH_MAX, "%s/%s", real_path, attrs[i]);
@@ -3180,8 +3172,7 @@ static int parse_config_sysfs_file(int maj, int min,
     unsigned char config[64];
     int fd, ret;
 
-    if (get_real_pci_path(maj, min, real_path) == NULL)
-        get_normal_pci_path(maj, min, real_path);
+    get_real_pci_path(maj, min, real_path);
 
     snprintf(path, PATH_MAX, "%s/config", real_path);
     fd = open(path, O_RDONLY);
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 xf86drm: rename "real_path" to "pci_path"

"real_path" was getting confusing when there are other *paths in the same functions.

---
 xf86drm.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
xf86drm.c +13 -13
index 649d400bcbc494ac04e6..b2388194932754dadc99 100644
@@ -2999,17 +2999,17 @@ static int drmParseSubsystemType(int maj, int min)
 }
 
 static void
-get_real_pci_path(int maj, int min, char *real_path)
+get_pci_path(int maj, int min, char *pci_path)
 {
     char path[PATH_MAX + 1], *term;
 
     snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
-    if (!realpath(path, real_path)) {
-        strcpy(real_path, path);
+    if (!realpath(path, pci_path)) {
+        strcpy(pci_path, path);
         return;
     }
 
-    term = strrchr(real_path, '/');
+    term = strrchr(pci_path, '/');
     if (term && strncmp(term, "/virtio", 7) == 0)
         *term = 0;
 }
@@ -3018,12 +3018,12 @@ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
 {
 #ifdef __linux__
     unsigned int domain, bus, dev, func;
-    char real_path[PATH_MAX + 1], *value;
+    char pci_path[PATH_MAX + 1], *value;
     int num;
 
-    get_real_pci_path(maj, min, real_path);
+    get_pci_path(maj, min, pci_path);
 
-    value = sysfs_uevent_get(real_path, "PCI_SLOT_NAME");
+    value = sysfs_uevent_get(pci_path, "PCI_SLOT_NAME");
     if (!value)
         return -ENOENT;
 
@@ -3136,15 +3136,15 @@ static int parse_separate_sysfs_files(int maj, int min,
       "subsystem_vendor",
       "subsystem_device",
     };
-    char path[PATH_MAX + 1], real_path[PATH_MAX + 1];
+    char path[PATH_MAX + 1], pci_path[PATH_MAX + 1];
     unsigned int data[ARRAY_SIZE(attrs)];
     FILE *fp;
     int ret;
 
-    get_real_pci_path(maj, min, real_path);
+    get_pci_path(maj, min, pci_path);
 
     for (unsigned i = ignore_revision ? 1 : 0; i < ARRAY_SIZE(attrs); i++) {
-        snprintf(path, PATH_MAX, "%s/%s", real_path, attrs[i]);
+        snprintf(path, PATH_MAX, "%s/%s", pci_path, attrs[i]);
         fp = fopen(path, "r");
         if (!fp)
             return -errno;
@@ -3168,13 +3168,13 @@ static int parse_separate_sysfs_files(int maj, int min,
 static int parse_config_sysfs_file(int maj, int min,
                                    drmPciDeviceInfoPtr device)
 {
-    char path[PATH_MAX + 1], real_path[PATH_MAX + 1];
+    char path[PATH_MAX + 1], pci_path[PATH_MAX + 1];
     unsigned char config[64];
     int fd, ret;
 
-    get_real_pci_path(maj, min, real_path);
+    get_pci_path(maj, min, pci_path);
 
-    snprintf(path, PATH_MAX, "%s/config", real_path);
+    snprintf(path, PATH_MAX, "%s/config", pci_path);
     fd = open(path, O_RDONLY);
     if (fd < 0)
         return -errno;
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/2
#2 lore raw
In reply to Eric Engestrom

Hi Eric,

Quoted 4 lines · Eric Engestrom
xf86drm.c +1 -1
-static char *
+static void
 get_real_pci_path(int maj, int min, char *real_path)

xf86drm.c static int drmParseSubsystemType(int maj, int min) · line 3010

Quoted 10 lines
xf86drm.c +4 -2
 {
     char path[PATH_MAX + 1], *term;
 
     snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
-    if (!realpath(path, real_path))
-        return NULL;
+    if (!realpath(path, real_path)) {
+        strcpy(real_path, path);
+        return;
+    }

I'm slightly inclined towards squashing this with 2/2 since as-is the function name is misleading.

Either way, for the lot:

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel