Skip to contentSkip to conversation

selftests/proc: fix unused result warning during test compilation

PATCH New Abhinav Jain 1 participant 1 message Jun 29, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/proc: fix unused result warning during test compilation

Check the return value from write function to get rid of the warning during test compilation, shared below.
Tested by compiling after the change, the warning disappears.

proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
385 | write(1, buf, rv);

---
Changes since v1:
- Remove the redundant if(0) block as per the feedback
- Patch v1:
https://lore.kernel.org/all/[email protected]/

---
 tools/testing/selftests/proc/proc-empty-vm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/proc/proc-empty-vm.c +6 -2
index 56198d4ca2bf..123c622cd816 100644
@@ -381,8 +381,12 @@ static int test_proc_pid_statm(pid_t pid)
 
 	assert(rv >= 0);
 	assert(rv <= sizeof(buf));
-	if (0) {
-		write(1, buf, rv);
+
+	ssize_t bytes_written = write(1, buf, rv);
+
+	if (bytes_written != rv) {
+		perror("write");
+		return EXIT_FAILURE;
 	}
 
 	const char *p = buf;
Signature · 1 line
2.34.1