Skip to contentSkip to conversation

lib/igt_sysfs: Let igt_sysfs_read|write return -errno

PATCH Superseded Michal Wajdeczko 3 participants 3 messages Dec 6, 2017 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/igt_sysfs: Let igt_sysfs_read|write return -errno

In some cases debugfs or sysfs may return errors that we want to check. Return -errno from helper functions to make asserts easier.

Cc Chris Wilson <[email protected]>
Cc Joonas Lahtinen <[email protected]>
---
 lib/igt_sysfs.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
lib/igt_sysfs.c +9 -9
index e7c67da..9e9fdde 100644
@@ -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')
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#1 lore raw

Quoting Michal Wajdeczko (2017-12-06 19:00:22)

Quoted 16 lines

In some cases debugfs or sysfs may return errors that we want to check. Return -errno from helper functions to make asserts easier.

Cc Chris Wilson <[email protected]>
Cc Joonas Lahtinen <[email protected]>
---
 lib/igt_sysfs.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
lib/igt_sysfs.c +0 -0
index e7c67da..9e9fdde 100644

lib/igt_sysfs.c static int readN(int fd, char *buf, int len) · line 64

Quoted 7 lines
lib/igt_sysfs.c +2 -2
@@ -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;

We do need to keep the break on ret == 0; some fs will just keep on reporting 0 bytes read for EOF.

How about

if (ret < 0) {
	ret = -errno;
	if (ret == -EINTR || ret == -EAGAIN)
		continue;
}

if (ret <= 0)

	return total ?: ret;

lib/igt_sysfs.c static int writeN(int fd, const char *buf, int len) · line 81

Quoted 11 lines
lib/igt_sysfs.c +2 -2
                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;

Ditto.

-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

✗ Fi.CI.BAT: failure for lib/igt_sysfs: Let igt_sysfs_read|write return -errno

In reply to Michal Wajdeczko
== Series Details ==

== Series Details ==

Series: lib/igt_sysfs: Let igt_sysfs_read|write return -errno
URL : https://patchwork.freedesktop.org/series/34989/
State : failure

== Summary ==

IGT patchset tested on top of latest successful build 1db12466cb5ad8483cd469753d2e312a62d717b7 meson: build a full dependency for lib_igt_perf

with latest DRM-Tip kernel build CI_DRM_3466
66be57731a40 drm-tip: 2017y-12m-06d-16h-12m-57s UTC integration manifest

No testlist changes.

Test debugfs_test:

        Subgroup read_all_entries:
                dmesg-warn -> PASS       (fi-elk-e7500) fdo#103989
Test drv_hangman:
        Subgroup error-state-basic:
                pass       -> INCOMPLETE (fi-gdg-551)
                pass       -> INCOMPLETE (fi-blb-e6850)
                pass       -> INCOMPLETE (fi-pnv-d510)
                pass       -> INCOMPLETE (fi-bwr-2160)
                pass       -> INCOMPLETE (fi-elk-e7500)
                pass       -> INCOMPLETE (fi-snb-2520m)
                pass       -> INCOMPLETE (fi-snb-2600)
                pass       -> INCOMPLETE (fi-ivb-3520m)
                pass       -> INCOMPLETE (fi-ivb-3770)
                pass       -> INCOMPLETE (fi-byt-j1900)
                pass       -> INCOMPLETE (fi-byt-n2820)
                pass       -> INCOMPLETE (fi-hsw-4770)
                pass       -> INCOMPLETE (fi-hsw-4770r)
                pass       -> INCOMPLETE (fi-bdw-5557u)
                pass       -> INCOMPLETE (fi-bsw-n3050)
                pass       -> INCOMPLETE (fi-skl-6260u)
                pass       -> INCOMPLETE (fi-skl-6600u)
                pass       -> INCOMPLETE (fi-skl-6700hq)
                pass       -> INCOMPLETE (fi-skl-6700k)
                pass       -> INCOMPLETE (fi-skl-6770hq)
                pass       -> INCOMPLETE (fi-bxt-dsi)
                pass       -> INCOMPLETE (fi-bxt-j4205)
                pass       -> INCOMPLETE (fi-kbl-7560u)
                pass       -> INCOMPLETE (fi-kbl-7567u)
                pass       -> INCOMPLETE (fi-kbl-r)
                pass       -> INCOMPLETE (fi-glk-1)

fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989

fi-bdw-5557u     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-blb-e6850     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-bsw-n3050     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-bwr-2160      total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-bxt-dsi       total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-bxt-j4205     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-byt-j1900     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-byt-n2820     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-elk-e7500     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-gdg-551       total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-glk-1         total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-hsw-4770      total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-hsw-4770r     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-ivb-3520m     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-ivb-3770      total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-kbl-7560u     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-kbl-7567u     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-kbl-r         total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-pnv-d510      total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6260u     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6600u     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6700hq    total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6700k     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6770hq    total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-snb-2520m     total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-snb-2600      total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
Blacklisted hosts:
fi-cfl-s2        total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-cnl-y         total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  
fi-glk-dsi       total:6    pass:5    dwarn:0   dfail:0   fail:0   skip:0  

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_604/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx