diff options
author | Emil Velikov <emil.l.velikov@gmail.com> | 2015-09-07 12:54:27 +0100 |
---|---|---|
committer | Emil Velikov <emil.l.velikov@gmail.com> | 2015-09-21 17:42:46 +0100 |
commit | a250fceaaa150363accaf3fb71a0e42bcecc40da (patch) | |
tree | 2ccd6ca6490f59eb0e60b9cd56042901389b4bae /xf86drm.c | |
parent | ef5192e9c7897c82da815a2c893b2e2562997a3a (diff) |
xf86drm: move the final linux specific bits out of drmGetDevices
Third and final piece of making drmGetDevices less crazy/ugly.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'xf86drm.c')
-rw-r--r-- | xf86drm.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -2835,21 +2835,23 @@ char *drmGetRenderDeviceNameFromFd(int fd) } #ifdef __linux__ -static int drmParseSubsystemType(const char *str) +static int drmParseSubsystemType(int maj, int min) { + char path[PATH_MAX + 1]; char link[PATH_MAX + 1] = ""; char *name; - if (readlink(str, link, PATH_MAX) < 0) - return -EINVAL; + snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem", + maj, min); + + if (readlink(path, link, PATH_MAX) < 0) + return -errno; name = strrchr(link, '/'); if (!name) return -EINVAL; - name++; - - if (strncmp(name, "pci", 3) == 0) + if (strncmp(name, "/pci", 4) == 0) return DRM_BUS_PCI; return -EINVAL; @@ -3001,7 +3003,6 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) struct dirent *dent = NULL; struct stat sbuf = {0}; char node[PATH_MAX + 1] = ""; - char path[PATH_MAX + 1] = ""; int node_type, subsystem_type; int maj, min; int ret, i = 0, j, node_count, device_count = 0; @@ -3033,9 +3034,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) continue; - snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem", - maj, min); - subsystem_type = drmParseSubsystemType(path); + subsystem_type = drmParseSubsystemType(maj, min); if (subsystem_type < 0) continue; |