summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2015-04-30 14:13:28 +0200
committerAlex Deucher <alexander.deucher@amd.com>2015-07-30 00:11:09 -0400
commitfe655b36d04a88dba4c480d5c28f054c7d3d6ba7 (patch)
treee26b45252f255371f029f92ba932ce624a273166
parent3173daacf190922a50ed55a67bf40adf7c9e1125 (diff)
amdgpu: compare the primary device names instead
Instead of taking a look at the device major/minor we just compare the primary device name to figure out if two fds are pointing to the same device. Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Christian König <christian.koenig@amd.com>
-rw-r--r--amdgpu/amdgpu_device.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index c610fd38..b50ce26a 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -42,7 +42,6 @@
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
#define UINT_TO_PTR(x) ((void *)((intptr_t)(x)))
-#define RENDERNODE_MINOR_MASK 0xff7f
pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct util_hash_table *fd_tab;
@@ -60,30 +59,40 @@ static int handle_compare(void *key1, void *key2)
static unsigned fd_hash(void *key)
{
int fd = PTR_TO_UINT(key);
- struct stat stat;
- fstat(fd, &stat);
+ char *name = drmGetPrimaryDeviceNameFromFd(fd);
+ unsigned result = 0;
+ char *c;
- if (!S_ISCHR(stat.st_mode))
- return stat.st_dev ^ stat.st_ino;
- else
- return stat.st_dev ^ (stat.st_rdev & RENDERNODE_MINOR_MASK);
+ if (name == NULL)
+ return 0;
+
+ for (c = name; *c; ++c)
+ result += *c;
+
+ free(name);
+
+ return result;
}
static int fd_compare(void *key1, void *key2)
{
int fd1 = PTR_TO_UINT(key1);
int fd2 = PTR_TO_UINT(key2);
- struct stat stat1, stat2;
- fstat(fd1, &stat1);
- fstat(fd2, &stat2);
-
- if (!S_ISCHR(stat1.st_mode) || !S_ISCHR(stat2.st_mode))
- return stat1.st_dev != stat2.st_dev ||
- stat1.st_ino != stat2.st_ino;
- else
- return major(stat1.st_rdev) != major(stat2.st_rdev) ||
- (minor(stat1.st_rdev) & RENDERNODE_MINOR_MASK) !=
- (minor(stat2.st_rdev) & RENDERNODE_MINOR_MASK);
+ char *name1 = drmGetPrimaryDeviceNameFromFd(fd1);
+ char *name2 = drmGetPrimaryDeviceNameFromFd(fd2);
+ int result;
+
+ if (name1 == NULL || name2 == NULL) {
+ free(name1);
+ free(name2);
+ return 0;
+ }
+
+ result = strcmp(name1, name2);
+ free(name1);
+ free(name2);
+
+ return result;
}
/**