commit bd3e6136568bbc5f88fdcd418ea275c11f3c3c12
parent efe0a1ed1856a2e4a1893ed0f2d7dde43b5627f0
Author: Michael Forney <mforney@mforney.org>
Date: Sat, 19 Aug 2017 18:47:09 -0700
Handle failure to open DRM vendor and device files
Diffstat:
| M | drm.c | | | 15 | +++++++++------ |
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drm.c b/drm.c
@@ -48,25 +48,25 @@ static const struct drm_driver * find_driver(int fd)
if (fstat(fd, &st) == -1)
return NULL;
- path_part = path + snprintf(path, sizeof path,
- "/sys/dev/char/%u:%u/device/",
- major(st.st_rdev), minor(st.st_rdev));
+ if (getenv("WLD_DRM_DUMB"))
+ goto dumb;
strcpy(path_part, "vendor");
file = fopen(path, "r");
+ if (!file)
+ goto dumb;
fgets(id, sizeof id, file);
fclose(file);
vendor_id = strtoul(id, NULL, 0);
strcpy(path_part, "device");
file = fopen(path, "r");
+ if (!file)
+ goto dumb;
fgets(id, sizeof id, file);
fclose(file);
device_id = strtoul(id, NULL, 0);
- if (getenv("WLD_DRM_DUMB"))
- return &dumb_drm_driver;
-
for (index = 0; index < ARRAY_LENGTH(drivers); ++index)
{
DEBUG("Trying DRM driver `%s'\n", drivers[index]->name);
@@ -77,6 +77,9 @@ static const struct drm_driver * find_driver(int fd)
DEBUG("No DRM driver supports device 0x%x:0x%x\n", vendor_id, device_id);
return NULL;
+
+dumb:
+ return &dumb_drm_driver;
}
EXPORT