[Mesa-dev] [PATCH] loader: fix sysfs uevent file parsing

Frank Binns frank.binns at imgtec.com
Fri Jun 17 17:29:40 UTC 2016


When trying to get a device name for an fd using sysfs, it would always fail
as it was expecting key/value pairs to be delimited by '\0', which is not the
case.

Signed-off-by: Frank Binns <frank.binns at imgtec.com>
---
 src/loader/loader.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 0348759..7221141 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -642,7 +642,7 @@ sysfs_get_device_name_for_fd(int fd)
    unsigned int maj, min;
    FILE *f;
    char buf[0x40];
-   static const char match[9] = "\0DEVNAME=";
+   static const char match[9] = "\nDEVNAME=";
    int expected = 1;
 
    if (dev_node_from_fd(fd, &maj, &min) < 0)
@@ -665,8 +665,10 @@ sysfs_get_device_name_for_fd(int fd)
    }
 
    strcpy(buf, "/dev/");
-   if (fgets(buf + 5, sizeof(buf) - 5, f))
+   if (fgets(buf + 5, sizeof(buf) - 5, f)) {
+      buf[strcspn(buf, "\n")] = '\0';
       device_name = strdup(buf);
+   }
 
    fclose(f);
    return device_name;
-- 
2.7.4



More information about the mesa-dev mailing list