2023-11-29 03:46:45

by angquan yu

[permalink] [raw]
Subject: [PATCH] selftests:proc: Resolve 'Unused Result' Warning from proc-empty-vm.c

From: angquan yu <[email protected]>

In tools/testing/selftests/proc/proc-empty->because the return value
of a write call was being ignored. This call was partof a conditional
debugging block (if (0) { ... }), which meant it would neveractually
execute.

This patch removes the unused debug write call. This cleanup resolves
the compi>warning about ignoring the result of write declared with
the warn_unused_resultattribute.

Removing this code also improves the clarity and maintainability of
the function, as it eliminates a non-functional block of code.

This is original warning: proc-empty-vm.c: In function
‘test_proc_pid_statm’ :proc-empty-vm.c:385:17:
warning: ignoring return value of ‘write’
declared with>385 | write(1, buf, rv);|

Signed-off-by: angquan yu <[email protected]>
---
tools/testing/selftests/proc/proc-empty-vm.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
index 5e7020630..d231e61e4 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -383,8 +383,10 @@ static int test_proc_pid_statm(pid_t pid)
assert(rv <= sizeof(buf));
if (0) {
ssize_t written = write(1, buf, rv);
+
if (written == -1) {
perror("write failed to /proc/${pid}");
+ return EXIT_FAILURE;
}
}

--
2.39.2


2023-11-30 20:25:51

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH] selftests:proc: Resolve 'Unused Result' Warning from proc-empty-vm.c

On 11/28/23 20:45, angquan yu wrote:
> From: angquan yu <[email protected]>
>
> In tools/testing/selftests/proc/proc-empty->because the return value
> of a write call was being ignored. This call was partof a conditional
> debugging block (if (0) { ... }), which meant it would neveractually
> execute.
>
> This patch removes the unused debug write call. This cleanup resolves
> the compi>warning about ignoring the result of write declared with
> the warn_unused_resultattribute.
>
> Removing this code also improves the clarity and maintainability of
> the function, as it eliminates a non-functional block of code.
>
> This is original warning: proc-empty-vm.c: In function
> ‘test_proc_pid_statm’ :proc-empty-vm.c:385:17:
> warning: ignoring return value of ‘write’
> declared with>385 | write(1, buf, rv);|
>
> Signed-off-by: angquan yu <[email protected]>
> ---
> tools/testing/selftests/proc/proc-empty-vm.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
> index 5e7020630..d231e61e4 100644
> --- a/tools/testing/selftests/proc/proc-empty-vm.c
> +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> @@ -383,8 +383,10 @@ static int test_proc_pid_statm(pid_t pid)
> assert(rv <= sizeof(buf));
> if (0) {
> ssize_t written = write(1, buf, rv);
> +
> if (written == -1) {
> perror("write failed to /proc/${pid}");
> + return EXIT_FAILURE;
> }
> }
>

Hmm. Is this patch based on Linux 6.7-rc3? The code doesn't
match?

thanks,
-- Shuah