xf86drm: introduce drm_device_has_rdev() helper

Currently we match the opened drmDevice fd with each drmDevice we
process.

Move that after all the devices are processed and folded, via the
drm_device_has_rdev(). This makes the code easier to follow and allows
us to unify the massive process loop across drmGetDevice2 and
drmGetDevices2. That in itself is coming with a later commit.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
main
Emil Velikov 2018-06-21 16:06:35 +01:00 committed by Emil Velikov
parent 7f52a0ebf7
commit 56e72d3f2e
1 changed files with 25 additions and 9 deletions

View File

@ -3705,6 +3705,21 @@ drm_device_validate_flags(uint32_t flags)
return (flags & ~DRM_DEVICE_GET_PCI_REVISION);
}
static bool
drm_device_has_rdev(drmDevicePtr device, dev_t find_rdev)
{
struct stat sbuf;
for (int i = 0; i < DRM_NODE_MAX; i++) {
if (device->available_nodes & 1 << i) {
if (stat(device->nodes[i], &sbuf) == 0 &&
sbuf.st_rdev == find_rdev)
return true;
}
}
return false;
}
/**
* Get information about the opened drm device
*
@ -3889,12 +3904,6 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
local_devices = temp;
}
/* 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++;
}
@ -3902,8 +3911,15 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
drmFoldDuplicatedDevices(local_devices, node_count);
*device = local_devices[0];
drmFreeDevices(&local_devices[1], node_count - 1);
for (i = 0; i < node_count; i++) {
if (!local_devices[i])
continue;
if (drm_device_has_rdev(local_devices[i], find_rdev))
*device = local_devices[i];
else
drmFreeDevice(&local_devices[i]);
}
closedir(sysdir);
free(local_devices);