commit bd3e613

Michael Forney  ·  2017-08-20 01:47:09 +0000 UTC
parent efe0a1e
Handle failure to open DRM vendor and device files
1 files changed,  +9, -6
M drm.c
M drm.c
+9, -6
 1@@ -48,25 +48,25 @@ static const struct drm_driver * find_driver(int fd)
 2     if (fstat(fd, &st) == -1)
 3         return NULL;
 4 
 5-    path_part = path + snprintf(path, sizeof path,
 6-                                "/sys/dev/char/%u:%u/device/",
 7-                                major(st.st_rdev), minor(st.st_rdev));
 8+    if (getenv("WLD_DRM_DUMB"))
 9+        goto dumb;
10 
11     strcpy(path_part, "vendor");
12     file = fopen(path, "r");
13+    if (!file)
14+        goto dumb;
15     fgets(id, sizeof id, file);
16     fclose(file);
17     vendor_id = strtoul(id, NULL, 0);
18 
19     strcpy(path_part, "device");
20     file = fopen(path, "r");
21+    if (!file)
22+        goto dumb;
23     fgets(id, sizeof id, file);
24     fclose(file);
25     device_id = strtoul(id, NULL, 0);
26 
27-    if (getenv("WLD_DRM_DUMB"))
28-        return &dumb_drm_driver;
29-
30     for (index = 0; index < ARRAY_LENGTH(drivers); ++index)
31     {
32         DEBUG("Trying DRM driver `%s'\n", drivers[index]->name);
33@@ -77,6 +77,9 @@ static const struct drm_driver * find_driver(int fd)
34     DEBUG("No DRM driver supports device 0x%x:0x%x\n", vendor_id, device_id);
35 
36     return NULL;
37+
38+dumb:
39+    return &dumb_drm_driver;
40 }
41 
42 EXPORT