drm-shim: return device platform as specified
[mesa.git] / src / drm-shim / drm_shim.c
index 7c7d5f0f0092080b81b6246b71358a9c17814477..e6f7bf9e9924a10c03f417a5ae7237ea825be31a 100644 (file)
@@ -219,6 +219,7 @@ PUBLIC FILE *fopen(const char *path, const char *mode)
          pipe(fds);
          write(fds[1], file_overrides[i].contents,
                strlen(file_overrides[i].contents));
+         close(fds[1]);
          return fdopen(fds[0], "r");
       }
    }
@@ -451,8 +452,26 @@ readlink(const char *path, char *buf, size_t size)
 
    if (strcmp(path, subsystem_path) != 0)
       return real_readlink(path, buf, size);
-   strncpy(buf, "/platform", size);
-   buf[size - 1] = 0;
+
+   static const struct {
+      const char *name;
+      int bus_type;
+   } bus_types[] = {
+      { "/pci", DRM_BUS_PCI },
+      { "/usb", DRM_BUS_USB },
+      { "/platform", DRM_BUS_PLATFORM },
+      { "/spi", DRM_BUS_PLATFORM },
+      { "/host1x", DRM_BUS_HOST1X },
+   };
+
+   for (uint32_t i = 0; i < ARRAY_SIZE(bus_types); i++) {
+      if (bus_types[i].bus_type != shim_device.bus_type)
+         continue;
+
+      strncpy(buf, bus_types[i].name, size);
+      buf[size - 1] = 0;
+      break;
+   }
 
    return strlen(buf) + 1;
 }