[PATCH] selftests/proc: fix unused result warning during test compilation

Abhinav Jain posted 1 patch 1 year, 5 months ago
There is a newer version of this series
tools/testing/selftests/proc/proc-empty-vm.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] selftests/proc: fix unused result warning during test compilation
Posted by Abhinav Jain 1 year, 5 months ago
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);

Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
 tools/testing/selftests/proc/proc-empty-vm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c
index 56198d4ca2bf..510ab4a5330a 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -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;
-- 
2.34.1

Re: [PATCH] selftests/proc: fix unused result warning during test compilation
Posted by Andrew Morton 1 year, 5 months ago
On Tue, 25 Jun 2024 15:21:39 +0000 Abhinav Jain <jain.abhinav177@gmail.com> wrote:

> 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);
> 
> ...
>
> --- a/tools/testing/selftests/proc/proc-empty-vm.c
> +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> @@ -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;
> +		}
>  	}

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

https://lkml.kernel.org/r/20240603124220.33778-1-amer.shanawany@gmail.com
Re: [PATCH] selftests/proc: fix unused result warning during test compilation
Posted by Abhinav Jain 1 year, 5 months ago
On Tue, 25 Jun 2024 11:05:26 -0700, Andrew Morton wrote:
> Thanks.  There's a patch queued which simply deletes this code.
>
> https://lkml.kernel.org/r/20240603124220.33778-1-amer.shanawany@gmail.com

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
Re: [PATCH] selftests/proc: fix unused result warning during test compilation
Posted by Andrew Morton 1 year, 5 months ago
On Fri, 28 Jun 2024 07:03:38 +0000 Abhinav Jain <jain.abhinav177@gmail.com> wrote:

> On Tue, 25 Jun 2024 11:05:26 -0700, Andrew Morton wrote:
> > Thanks.  There's a patch queued which simply deletes this code.
> >
> > https://lkml.kernel.org/r/20240603124220.33778-1-amer.shanawany@gmail.com
> 
> 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.
Re: [PATCH] selftests/proc: fix unused result warning during test compilation
Posted by Abhinav Jain 1 year, 5 months ago
On Fri, 28 Jun 2024 13:30:14 -0700, Andrew Morton wrote:
> Well, it's all inside `if (0)', so just remove it.

Removed and shared v2 version of the patch here:
https://lore.kernel.org/all/20240629050449.990451-1-jain.abhinav177@gmail.com/

Please review. Thanks.