From: Qiang Yu <Qiang.Yu@amd.com>
To: amd-gfx@lists.freedesktop.org
Cc: Qiang Yu <Qiang.Yu@amd.com>, dri-devel@lists.freedesktop.org
Subject: [PATCH][libdrm] drm: Fix multi GPU drmGetDevice return wrong device
Date: Mon, 11 Jul 2016 13:17:25 +0800 [thread overview]
Message-ID: <1468214245-4716-1-git-send-email-Qiang.Yu@amd.com> (raw)
drmGetDevice will always return the first device it find
under /dev/dri/. This is not true for multi GPU situation.
Plus fix the memory leak in error handling path of
drmGetDevices.
Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
---
xf86drm.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index 6689f7c..e90e8e5 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3064,6 +3064,17 @@ static void drmFoldDuplicatedDevices(drmDevicePtr local_devices[], int count)
}
}
}
+
+ // move all devices to the beginning of local_devices continuously
+ for (i = 0, j = 0; i < count; i++) {
+ if (local_devices[i]) {
+ if (i != j) {
+ local_devices[j] = local_devices[i];
+ local_devices[i] = NULL;
+ }
+ j++;
+ }
+ }
}
/**
@@ -3087,6 +3098,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 +3106,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,7 +3167,13 @@ int drmGetDevice(int fd, drmDevicePtr *device)
local_devices = temp;
}
- local_devices[i] = d;
+ /* move target to the first of local_devices */
+ 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;
@@ -3267,10 +3286,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
drmFoldDuplicatedDevices(local_devices, node_count);
device_count = 0;
- for (i = 0; i < node_count; i++) {
- if (!local_devices[i])
- continue;
-
+ for (i = 0; i < node_count && local_devices[i]; i++) {
if ((devices != NULL) && (device_count < max_devices))
devices[device_count] = local_devices[i];
else
--
1.9.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next reply other threads:[~2016-07-11 5:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-11 5:17 Qiang Yu [this message]
2016-07-13 9:47 ` [PATCH][libdrm] drm: Fix multi GPU drmGetDevice return wrong device Emil Velikov
2016-07-13 10:17 ` Yu, Qiang
2016-07-13 11:15 ` Emil Velikov
2016-07-14 3:02 ` Yu, Qiang
2016-07-14 16:14 ` Emil Velikov
2016-07-15 1:22 ` Yu, Qiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1468214245-4716-1-git-send-email-Qiang.Yu@amd.com \
--to=qiang.yu@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox