mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-30 17:50:17 +01:00
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>
This commit is contained in:
parent
04a09e8969
commit
5f486123e3
1 changed files with 26 additions and 17 deletions
|
|
@ -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);
|
||||
char *name1 = drmGetPrimaryDeviceNameFromFd(fd1);
|
||||
char *name2 = drmGetPrimaryDeviceNameFromFd(fd2);
|
||||
int result;
|
||||
|
||||
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);
|
||||
if (name1 == NULL || name2 == NULL) {
|
||||
free(name1);
|
||||
free(name2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = strcmp(name1, name2);
|
||||
free(name1);
|
||||
free(name2);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue