In some cases debugfs or sysfs may return errors that we want to check. Return -errno from helper functions to make asserts easier. Signed-off-by: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx> Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx> --- lib/igt_sysfs.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c index e7c67da..9e9fdde 100644 --- a/lib/igt_sysfs.c +++ b/lib/igt_sysfs.c @@ -60,8 +60,8 @@ static int readN(int fd, char *buf, int len) if (ret < 0 && (errno == EINTR || errno == EAGAIN)) continue; - if (ret <= 0) - return total ?: ret; + if (ret < 0) + return total ?: -errno; total += ret; if (total == len) @@ -77,8 +77,8 @@ static int writeN(int fd, const char *buf, int len) if (ret < 0 && (errno == EINTR || errno == EAGAIN)) continue; - if (ret <= 0) - return total ?: ret; + if (ret < 0) + return total ?: -errno; total += ret; if (total == len) @@ -238,7 +238,7 @@ int igt_sysfs_open_parameters(int device) * This writes @len bytes from @data to the sysfs file. * * Returns: - * The number of bytes written, or -1 on error. + * The number of bytes written, or -errno on error. */ int igt_sysfs_write(int dir, const char *attr, const void *data, int len) { @@ -246,7 +246,7 @@ int igt_sysfs_write(int dir, const char *attr, const void *data, int len) fd = openat(dir, attr, O_WRONLY); if (fd < 0) - return false; + return -errno; len = writeN(fd, data, len); close(fd); @@ -264,7 +264,7 @@ int igt_sysfs_write(int dir, const char *attr, const void *data, int len) * This reads @len bytes from the sysfs file to @data * * Returns: - * The length read, -1 on failure. + * The length read, -errno on failure. */ int igt_sysfs_read(int dir, const char *attr, void *data, int len) { @@ -272,7 +272,7 @@ int igt_sysfs_read(int dir, const char *attr, void *data, int len) fd = openat(dir, attr, O_RDONLY); if (fd < 0) - return false; + return -errno; len = readN(fd, data, len); close(fd); @@ -338,7 +338,7 @@ char *igt_sysfs_get(int dir, const char *attr) rem = len - offset - 1; } - if (ret != -1) + if (ret > 0) offset += ret; buf[offset] = '\0'; while (offset > 0 && buf[offset-1] == '\n') -- 2.7.4 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx