aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Velikov2015-09-07 06:54:27 -0500
committerEmil Velikov2015-09-21 11:42:46 -0500
commita250fceaaa150363accaf3fb71a0e42bcecc40da (patch)
tree2ccd6ca6490f59eb0e60b9cd56042901389b4bae /xf86drm.c
parentef5192e9c7897c82da815a2c893b2e2562997a3a (diff)
downloadexternal-libgbm-a250fceaaa150363accaf3fb71a0e42bcecc40da.tar.gz
external-libgbm-a250fceaaa150363accaf3fb71a0e42bcecc40da.tar.xz
external-libgbm-a250fceaaa150363accaf3fb71a0e42bcecc40da.zip
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.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/xf86drm.c b/xf86drm.c
index 1174a64e..dc1782d3 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2835,21 +2835,23 @@ char *drmGetRenderDeviceNameFromFd(int fd)
2835} 2835}
2836 2836
2837#ifdef __linux__ 2837#ifdef __linux__
2838static int drmParseSubsystemType(const char *str) 2838static int drmParseSubsystemType(int maj, int min)
2839{ 2839{
2840 char path[PATH_MAX + 1];
2840 char link[PATH_MAX + 1] = ""; 2841 char link[PATH_MAX + 1] = "";
2841 char *name; 2842 char *name;
2842 2843
2843 if (readlink(str, link, PATH_MAX) < 0) 2844 snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem",
2844 return -EINVAL; 2845 maj, min);
2846
2847 if (readlink(path, link, PATH_MAX) < 0)
2848 return -errno;
2845 2849
2846 name = strrchr(link, '/'); 2850 name = strrchr(link, '/');
2847 if (!name) 2851 if (!name)
2848 return -EINVAL; 2852 return -EINVAL;
2849 2853
2850 name++; 2854 if (strncmp(name, "/pci", 4) == 0)
2851
2852 if (strncmp(name, "pci", 3) == 0)
2853 return DRM_BUS_PCI; 2855 return DRM_BUS_PCI;
2854 2856
2855 return -EINVAL; 2857 return -EINVAL;
@@ -3001,7 +3003,6 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
3001 struct dirent *dent = NULL; 3003 struct dirent *dent = NULL;
3002 struct stat sbuf = {0}; 3004 struct stat sbuf = {0};
3003 char node[PATH_MAX + 1] = ""; 3005 char node[PATH_MAX + 1] = "";
3004 char path[PATH_MAX + 1] = "";
3005 int node_type, subsystem_type; 3006 int node_type, subsystem_type;
3006 int maj, min; 3007 int maj, min;
3007 int ret, i = 0, j, node_count, device_count = 0; 3008 int ret, i = 0, j, node_count, device_count = 0;
@@ -3033,9 +3034,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
3033 if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) 3034 if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
3034 continue; 3035 continue;
3035 3036
3036 snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem", 3037 subsystem_type = drmParseSubsystemType(maj, min);
3037 maj, min);
3038 subsystem_type = drmParseSubsystemType(path);
3039 3038
3040 if (subsystem_type < 0) 3039 if (subsystem_type < 0)
3041 continue; 3040 continue;