diff mbox series

selftests: proc: remove unreached code and fix build warning

Message ID 20240603124220.33778-1-amer.shanawany@gmail.com (mailing list archive)
State New
Headers show
Series selftests: proc: remove unreached code and fix build warning | expand

Commit Message

Amer Al Shanawany June 3, 2024, 12:42 p.m. UTC
fix the following warning:
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);
      |                 ^~~~~~~~~~~~~~~~~

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202404010211.ygidvMwa-lkp@intel.com/
Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com>
---
 tools/testing/selftests/proc/proc-empty-vm.c | 3 ---
 1 file changed, 3 deletions(-)

Comments

Alexey Dobriyan June 3, 2024, 2:24 p.m. UTC | #1
On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
> fix the following warning:
> proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’

> --- a/tools/testing/selftests/proc/proc-empty-vm.c
> +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)

> -	if (0) {
> -		write(1, buf, rv);
> -	}

no thanks
Andrew Morton June 5, 2024, 3:25 a.m. UTC | #2
On Mon, 3 Jun 2024 17:24:47 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:

> On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
> > fix the following warning:
> > proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
> 
> > --- a/tools/testing/selftests/proc/proc-empty-vm.c
> > +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> > @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
> 
> > -	if (0) {
> > -		write(1, buf, rv);
> > -	}
> 
> no thanks

Why not?

Why does that code exist anyway?  It at least needs a comment.
Alexey Dobriyan June 7, 2024, 3:25 p.m. UTC | #3
On Tue, Jun 04, 2024 at 08:25:31PM -0700, Andrew Morton wrote:
> On Mon, 3 Jun 2024 17:24:47 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
> > > fix the following warning:
> > > proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
> > 
> > > --- a/tools/testing/selftests/proc/proc-empty-vm.c
> > > +++ b/tools/testing/selftests/proc/proc-empty-vm.c
> > > @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
> > 
> > > -	if (0) {
> > > -		write(1, buf, rv);
> > > -	}
> > 
> > no thanks
> 
> Why not?
> 
> Why does that code exist anyway?  It at least needs a comment.

OK, whatever.

If test fails, it better record buggy output somewhere (to coredump or to terminal).
Shuah Khan June 11, 2024, 3:04 p.m. UTC | #4
On 6/7/24 09:25, Alexey Dobriyan wrote:
> On Tue, Jun 04, 2024 at 08:25:31PM -0700, Andrew Morton wrote:
>> On Mon, 3 Jun 2024 17:24:47 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
>>
>>> On Mon, Jun 03, 2024 at 02:42:20PM +0200, Amer Al Shanawany wrote:
>>>> fix the following warning:
>>>> proc-empty-vm.c:385:17: warning: ignoring return value of ‘write’
>>>
>>>> --- a/tools/testing/selftests/proc/proc-empty-vm.c
>>>> +++ b/tools/testing/selftests/proc/proc-empty-vm.c
>>>> @@ -381,9 +381,6 @@ static int test_proc_pid_statm(pid_t pid)
>>>
>>>> -	if (0) {
>>>> -		write(1, buf, rv);
>>>> -	}
>>>
>>> no thanks
>>
>> Why not?
>>
>> Why does that code exist anyway?  It at least needs a comment.
> 
> OK, whatever.
> 
> If test fails, it better record buggy output somewhere (to coredump or to terminal).

+1 on reporting results - the best way to do this is to add a meaningful message
for users to understand what went wrong.

Please suggest how you would like this warning addressed and report the error.

thanks,
-- Shuah
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..b3f898aab4ab 100644
--- a/tools/testing/selftests/proc/proc-empty-vm.c
+++ b/tools/testing/selftests/proc/proc-empty-vm.c
@@ -381,9 +381,6 @@  static int test_proc_pid_statm(pid_t pid)
 
 	assert(rv >= 0);
 	assert(rv <= sizeof(buf));
-	if (0) {
-		write(1, buf, rv);
-	}
 
 	const char *p = buf;
 	const char *const end = p + rv;