diff mbox series

selftests/proc: fix unused result warning during test compilation

Message ID 20240625152139.16412-1-jain.abhinav177@gmail.com (mailing list archive)
State New
Headers show
Series selftests/proc: fix unused result warning during test compilation | expand

Commit Message

Abhinav Jain June 25, 2024, 3:21 p.m. UTC
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(-)

Comments

Andrew Morton June 25, 2024, 6:05 p.m. UTC | #1
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
Abhinav Jain June 28, 2024, 7:03 a.m. UTC | #2
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
Andrew Morton June 28, 2024, 8:30 p.m. UTC | #3
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.
Abhinav Jain June 29, 2024, 5:08 a.m. UTC | #4
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.
diff mbox series

Patch

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;