drm: Fix multi GPU drmGetDevice return wrong device
PATCH v2 1/2 drm: Fix multi GPU drmGetDevice return wrong device
drmGetDevice will always return the first device it find under /dev/dri/. This is not true for multi GPU situation.
--- xf86drm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
xf86drm.c +13 -4
@@ -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);
Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 2/2 drm: fix multi GPU drmFreeDevices memory leak
When in multi GPU case, devices array may have some NULL "hole" in between two devices. So check all array elements and free non-NULL device.
--- xf86drm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xf86drm.c +3 -2
@@ -2992,8 +2992,9 @@ void drmFreeDevices(drmDevicePtr devices[], int count)if (devices ==NULL )return ; -for (i =0 ; i < count && devices[i] !=NULL ; i++) -drmFreeDevice (&devices[i]); +for (i =0 ; i < count; i++) +if (devices[i]) +drmFreeDevice (&devices[i]); } static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines · Qiang Yu
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:
Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines · Qiang Yu
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
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel