Skip to contentSkip to conversation

selftests/proc: fix unused result warning during test compilation

PATCH Superseded Abhinav Jain 2 participants 5 messages Jun 25, 2024 – Jun 29, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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);

---
 tools/testing/selftests/proc/proc-empty-vm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/proc/proc-empty-vm.c +6 -1
index 56198d4ca2bf..510ab4a5330a 100644
@@ -382,7 +382,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
#1 lore raw
Quoted 14 lines · On Tue, 25 Jun 2024 15:21:39 +0000 Abhinav Jain <[email protected]>…

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);

...

tools/testing/selftests/proc/proc-empty-vm.c +0 -0
@@ -382,7 +382,12 @@ static int test_proc_pid_statm(pid_t pid)
 	assert(rv >= 0);

tools/testing/selftests/proc/proc-empty-vm.c static int test_proc_pid_statm(pid_t pid) · line 391

Quoted 10 lines
tools/testing/selftests/proc/proc-empty-vm.c +6 -1
 	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;
+		}
 	}

Thanks. There's a patch queued which simply deletes this code.

https://lkml.kernel.org/r/[email protected]

#2 lore raw
Quoted 3 lines · Andrew Morton

Thanks. There's a patch queued which simply deletes this code.

https://lkml.kernel.org/r/[email protected]

Thank you for sharing the queued patch Andrew.
There has been no update/revert on it, may I know what would be the next step here? After reading the patch above, I believe my change is "more" right. Is that correct?

Thanks and Regards
- Abhinav

#3 lore raw
Quoted 9 lines · On Fri, 28 Jun 2024 07:03:38 +0000 Abhinav Jain <[email protected]>…
Quoted 3 lines · Andrew Morton

Thanks. There's a patch queued which simply deletes this code.

https://lkml.kernel.org/r/[email protected]

Thank you for sharing the queued patch Andrew.
There has been no update/revert on it, may I know what would be the next step here? After reading the patch above, I believe my change is "more" right. Is that correct?

Well, it's all inside `if (0)', so just remove it.