aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Gray2016-12-16 23:09:51 -0600
committerEmil Velikov2016-12-24 11:06:49 -0600
commitd5cf3f98314c1b9d87216e00c30c9fef06ff24c3 (patch)
tree16479426affd410a56731ac1b99a61e4eb1809a6 /xf86drm.c
parente3af5368b2c372cfda27bc010b9c98a923d83cd9 (diff)
downloadexternal-libgbm-d5cf3f98314c1b9d87216e00c30c9fef06ff24c3.tar.gz
external-libgbm-d5cf3f98314c1b9d87216e00c30c9fef06ff24c3.tar.xz
external-libgbm-d5cf3f98314c1b9d87216e00c30c9fef06ff24c3.zip
xf86drm: adjust device node path for minor base
When constructing a path to a device node the minor number retrieved from fstat needs to have the offset of the node type subtracted from it. Control and render node types have the same major as the primary node but each has their own block of minor types at fixed offsets. v2: remove min < base test as requested by Emil Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/xf86drm.c b/xf86drm.c
index b5eeeb09..f6850aa2 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2838,7 +2838,7 @@ out_close_dir:
2838 char buf[PATH_MAX + 1]; 2838 char buf[PATH_MAX + 1];
2839 const char *dev_name; 2839 const char *dev_name;
2840 unsigned int maj, min; 2840 unsigned int maj, min;
2841 int n; 2841 int n, base;
2842 2842
2843 if (fstat(fd, &sbuf)) 2843 if (fstat(fd, &sbuf))
2844 return NULL; 2844 return NULL;
@@ -2863,7 +2863,11 @@ out_close_dir:
2863 return NULL; 2863 return NULL;
2864 }; 2864 };
2865 2865
2866 n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min); 2866 base = drmGetMinorBase(type);
2867 if (base < 0)
2868 return NULL;
2869
2870 n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min - base);
2867 if (n == -1 || n >= sizeof(buf)) 2871 if (n == -1 || n >= sizeof(buf))
2868 return NULL; 2872 return NULL;
2869 2873
@@ -3262,7 +3266,7 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
3262 char node[PATH_MAX + 1]; 3266 char node[PATH_MAX + 1];
3263 const char *dev_name; 3267 const char *dev_name;
3264 int node_type, subsystem_type; 3268 int node_type, subsystem_type;
3265 int maj, min, n, ret; 3269 int maj, min, n, ret, base;
3266 3270
3267 if (fd == -1 || device == NULL) 3271 if (fd == -1 || device == NULL)
3268 return -EINVAL; 3272 return -EINVAL;
@@ -3294,7 +3298,11 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
3294 return -EINVAL; 3298 return -EINVAL;
3295 }; 3299 };
3296 3300
3297 n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min); 3301 base = drmGetMinorBase(node_type);
3302 if (base < 0)
3303 return -EINVAL;
3304
3305 n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
3298 if (n == -1 || n >= PATH_MAX) 3306 if (n == -1 || n >= PATH_MAX)
3299 return -errno; 3307 return -errno;
3300 if (stat(node, &sbuf)) 3308 if (stat(node, &sbuf))