diff mbox series

[libdrm,RESEND,1/2] xf86drm: generalize the device subsystem type parsing code

Message ID 20200129183543.30023-1-Mikhail.Golubev@opensynergy.com (mailing list archive)
State New, archived
Headers show
Series [libdrm,RESEND,1/2] xf86drm: generalize the device subsystem type parsing code | expand

Commit Message

Mikhail Golubev Jan. 29, 2020, 6:35 p.m. UTC
From: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>

Move the code, which used to get the device subsystem type from a device
path in sysfs, to a separate function to be reusable.

Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
Signed-off-by: Mikhail Golubev <Mikhail.Golubev@opensynergy.com>
---
 xf86drm.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

Comments

Michel Dänzer Jan. 30, 2020, 3:27 p.m. UTC | #1
Hi Mikhail,


thanks for the patches.

Please create a merge request by clicking the "Fork" button on
https://gitlab.freedesktop.org/mesa/drm, pushing the two commits to a
new branch in the newly created repository, and opening the URL in the
"git push" output.

Thanks,
Mikhail Golubev Jan. 30, 2020, 5:06 p.m. UTC | #2
Hi Michel!

Thanks for reply.
Did create the merge request here:
https://gitlab.freedesktop.org/mesa/drm/merge_requests/43

BR,
Mikhail.

On 1/30/20 4:27 PM, Michel Dänzer wrote:
> 
> Hi Mikhail,
> 
> 
> thanks for the patches.
> 
> Please create a merge request by clicking the "Fork" button on
> https://gitlab.freedesktop.org/mesa/drm, pushing the two commits to a
> new branch in the newly created repository, and opening the URL in the
> "git push" output.
> 
> Thanks,
> 
>
diff mbox series

Patch

diff --git a/xf86drm.c b/xf86drm.c
index 7ae41c37..b1479128 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2964,10 +2964,10 @@  sysfs_uevent_get(const char *path, const char *fmt, ...)
 /* Little white lie to avoid major rework of the existing code */
 #define DRM_BUS_VIRTIO 0x10
 
-static int drmParseSubsystemType(int maj, int min)
-{
 #ifdef __linux__
-    char path[PATH_MAX + 1];
+static int get_subsystem_type(const char *device_path)
+{
+    char path[PATH_MAX + 1] = "";
     char link[PATH_MAX + 1] = "";
     char *name;
     struct {
@@ -2982,8 +2982,8 @@  static int drmParseSubsystemType(int maj, int min)
         { "/virtio", DRM_BUS_VIRTIO },
     };
 
-    snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem",
-             maj, min);
+    strncpy(path, device_path, PATH_MAX);
+    strncat(path, "/subsystem", PATH_MAX);
 
     if (readlink(path, link, PATH_MAX) < 0)
         return -errno;
@@ -2998,6 +2998,17 @@  static int drmParseSubsystemType(int maj, int min)
     }
 
     return -EINVAL;
+}
+#endif
+
+static int drmParseSubsystemType(int maj, int min)
+{
+#ifdef __linux__
+    char path[PATH_MAX + 1] = "";
+
+    snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device", maj, min);
+
+    return get_subsystem_type(path);
 #elif defined(__OpenBSD__) || defined(__DragonFly__)
     return DRM_BUS_PCI;
 #else