diff mbox

[libdrm,v2,1/2] drm: Fix multi GPU drmGetDevice return wrong device

Message ID 1468487456-28666-1-git-send-email-Qiang.Yu@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

Qiang Yu July 14, 2016, 9:10 a.m. UTC
drmGetDevice will always return the first device it find
under /dev/dri/. This is not true for multi GPU situation.

Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
---
 xf86drm.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Comments

Emil Velikov July 14, 2016, 5:20 p.m. UTC | #1
On 14 July 2016 at 10:10, Qiang Yu <Qiang.Yu@amd.com> wrote:
> drmGetDevice will always return the first device it find
> under /dev/dri/. This is not true for multi GPU situation.
>
> Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d
Hope you don't mind if I drop the change-id lines before committing ?

If anyone beats be to it, for the series:
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>

Thanks
Emil
Qiang Yu July 15, 2016, 1:19 a.m. UTC | #2
On 14 July 2016 at 10:10, Qiang Yu <Qiang.Yu@amd.com> wrote:
> drmGetDevice will always return the first device it find
> under /dev/dri/. This is not true for multi GPU situation.
>
> Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d
Hope you don't mind if I drop the change-id lines before committing ?

[yuq] Oh, I forgot remove this line. Please go ahead remove it, thanks.

Regards,
Qiang
diff mbox

Patch

diff --git a/xf86drm.c b/xf86drm.c
index 6689f7c..19001db 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3087,6 +3087,7 @@  int drmGetDevice(int fd, drmDevicePtr *device)
     int maj, min;
     int ret, i, node_count;
     int max_count = 16;
+    dev_t find_rdev;
 
     if (fd == -1 || device == NULL)
         return -EINVAL;
@@ -3094,6 +3095,7 @@  int drmGetDevice(int fd, drmDevicePtr *device)
     if (fstat(fd, &sbuf))
         return -errno;
 
+    find_rdev = sbuf.st_rdev;
     maj = major(sbuf.st_rdev);
     min = minor(sbuf.st_rdev);
 
@@ -3154,17 +3156,24 @@  int drmGetDevice(int fd, drmDevicePtr *device)
             local_devices = temp;
         }
 
-        local_devices[i] = d;
+        /* store target at local_devices[0] for ease to use below */
+        if (find_rdev == sbuf.st_rdev && i) {
+            local_devices[i] = local_devices[0];
+            local_devices[0] = d;
+        }
+        else
+            local_devices[i] = d;
         i++;
     }
     node_count = i;
 
-    /* Fold nodes into a single device if they share the same bus info */
+    /* Fold nodes into a single device if they share the same bus info
+     * and nodes with same bus info will be merged into the first node
+     * position in local_devices */
     drmFoldDuplicatedDevices(local_devices, node_count);
 
     *device = local_devices[0];
-    for (i = 1; i < node_count && local_devices[i]; i++)
-            drmFreeDevice(&local_devices[i]);
+    drmFreeDevices(&local_devices[1], node_count - 1);
 
     closedir(sysdir);
     free(local_devices);