[dpdk-dev] vhost: fix build issue caused by unchecked returned values

Message ID 20180330151641.20715-1-maxime.coquelin@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Maxime Coquelin March 30, 2018, 3:16 p.m. UTC
  This patch fixes below build issue seen with some compilers
or build options:

lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_read_cb’:
lib/librte_vhost/fd_man.c:284:2: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
  read(readfd, charbuf, sizeof(charbuf));
  ^
lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_notify’:
lib/librte_vhost/fd_man.c:324:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
  write(fdset->u.writefd, "1", 1);
  ^

Reported-by: Andrew Rybchenko <arybchenko@solarflare.com>
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/fd_man.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
  

Comments

Andrew Rybchenko March 30, 2018, 3:18 p.m. UTC | #1
On 03/30/2018 06:16 PM, Maxime Coquelin wrote:
> This patch fixes below build issue seen with some compilers
> or build options:
>
> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_read_cb’:
> lib/librte_vhost/fd_man.c:284:2: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
>    read(readfd, charbuf, sizeof(charbuf));
>    ^
> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_notify’:
> lib/librte_vhost/fd_man.c:324:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
>    write(fdset->u.writefd, "1", 1);
>    ^
>
> Reported-by: Andrew Rybchenko <arybchenko@solarflare.com>
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>   lib/librte_vhost/fd_man.c | 17 +++++++++++++++--
>   1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
> index ca1ba2622..1f9e22f96 100644
> --- a/lib/librte_vhost/fd_man.c
> +++ b/lib/librte_vhost/fd_man.c
> @@ -281,7 +281,13 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
>   		   int *remove __rte_unused)
>   {
>   	char charbuf[16];
> -	read(readfd, charbuf, sizeof(charbuf));
> +	int r = read(readfd, charbuf, sizeof(charbuf));
> +	/*
> +	 * Just an optimization, we don't care if read() failed
> +	 * so ignore explicitly its return value to make the
> +	 * compiler happy
> +	 */
> +	RTE_SET_USED(r);
>   }
>   
>   void
> @@ -321,5 +327,12 @@ fdset_pipe_init(struct fdset *fdset)
>   void
>   fdset_pipe_notify(struct fdset *fdset)
>   {
> -	write(fdset->u.writefd, "1", 1);
> +	int r = write(fdset->u.writefd, "1", 1);
> +	/*
> +	 * Just an optimization, we don't care if read() failed

read() -> write()

> +	 * so ignore explicitly its return value to make the
> +	 * compiler happy
> +	 */
> +	RTE_SET_USED(r);
> +
>   }
  
Ferruh Yigit March 30, 2018, 3:21 p.m. UTC | #2
On 3/30/2018 4:18 PM, Andrew Rybchenko wrote:
> On 03/30/2018 06:16 PM, Maxime Coquelin wrote:
>> This patch fixes below build issue seen with some compilers
>> or build options:
>>
>> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_read_cb’:
>> lib/librte_vhost/fd_man.c:284:2: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
>>   read(readfd, charbuf, sizeof(charbuf));
>>   ^
>> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_notify’:
>> lib/librte_vhost/fd_man.c:324:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
>>   write(fdset->u.writefd, "1", 1);
>>   ^
>>
>> Reported-by: Andrew Rybchenko <arybchenko@solarflare.com>
>> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>>  lib/librte_vhost/fd_man.c | 17 +++++++++++++++--
>>  1 file changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
>> index ca1ba2622..1f9e22f96 100644
>> --- a/lib/librte_vhost/fd_man.c
>> +++ b/lib/librte_vhost/fd_man.c
>> @@ -281,7 +281,13 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
>>  		   int *remove __rte_unused)
>>  {
>>  	char charbuf[16];
>> -	read(readfd, charbuf, sizeof(charbuf));
>> +	int r = read(readfd, charbuf, sizeof(charbuf));
>> +	/*
>> +	 * Just an optimization, we don't care if read() failed
>> +	 * so ignore explicitly its return value to make the
>> +	 * compiler happy
>> +	 */
>> +	RTE_SET_USED(r);
>>  }
>>  
>>  void
>> @@ -321,5 +327,12 @@ fdset_pipe_init(struct fdset *fdset)
>>  void
>>  fdset_pipe_notify(struct fdset *fdset)
>>  {
>> -	write(fdset->u.writefd, "1", 1);
>> +	int r = write(fdset->u.writefd, "1", 1);
>> +	/*
>> +	 * Just an optimization, we don't care if read() failed
> 
> read() -> write()

I can fix while applying.

> 
>> +	 * so ignore explicitly its return value to make the
>> +	 * compiler happy
>> +	 */
>> +	RTE_SET_USED(r);
>> +
>>  }
>
  
Maxime Coquelin March 30, 2018, 3:26 p.m. UTC | #3
On 03/30/2018 05:21 PM, Ferruh Yigit wrote:
> On 3/30/2018 4:18 PM, Andrew Rybchenko wrote:
>> On 03/30/2018 06:16 PM, Maxime Coquelin wrote:
>>> This patch fixes below build issue seen with some compilers
>>> or build options:
>>>
>>> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_read_cb’:
>>> lib/librte_vhost/fd_man.c:284:2: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
>>>    read(readfd, charbuf, sizeof(charbuf));
>>>    ^
>>> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_notify’:
>>> lib/librte_vhost/fd_man.c:324:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
>>>    write(fdset->u.writefd, "1", 1);
>>>    ^
>>>
>>> Reported-by: Andrew Rybchenko <arybchenko@solarflare.com>
>>> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
>>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>>> ---
>>>   lib/librte_vhost/fd_man.c | 17 +++++++++++++++--
>>>   1 file changed, 15 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
>>> index ca1ba2622..1f9e22f96 100644
>>> --- a/lib/librte_vhost/fd_man.c
>>> +++ b/lib/librte_vhost/fd_man.c
>>> @@ -281,7 +281,13 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
>>>   		   int *remove __rte_unused)
>>>   {
>>>   	char charbuf[16];
>>> -	read(readfd, charbuf, sizeof(charbuf));
>>> +	int r = read(readfd, charbuf, sizeof(charbuf));
>>> +	/*
>>> +	 * Just an optimization, we don't care if read() failed
>>> +	 * so ignore explicitly its return value to make the
>>> +	 * compiler happy
>>> +	 */
>>> +	RTE_SET_USED(r);
>>>   }
>>>   
>>>   void
>>> @@ -321,5 +327,12 @@ fdset_pipe_init(struct fdset *fdset)
>>>   void
>>>   fdset_pipe_notify(struct fdset *fdset)
>>>   {
>>> -	write(fdset->u.writefd, "1", 1);
>>> +	int r = write(fdset->u.writefd, "1", 1);
>>> +	/*
>>> +	 * Just an optimization, we don't care if read() failed
>>
>> read() -> write()
> 
> I can fix while applying.

Thanks!

> 
>>
>>> +	 * so ignore explicitly its return value to make the
>>> +	 * compiler happy
>>> +	 */
>>> +	RTE_SET_USED(r);
>>> +
>>>   }
>>
>
  
Ferruh Yigit March 30, 2018, 3:31 p.m. UTC | #4
On 3/30/2018 4:16 PM, Maxime Coquelin wrote:
> This patch fixes below build issue seen with some compilers
> or build options:
> 
> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_read_cb’:
> lib/librte_vhost/fd_man.c:284:2: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
>   read(readfd, charbuf, sizeof(charbuf));
>   ^
> lib/librte_vhost/fd_man.c: In function ‘fdset_pipe_notify’:
> lib/librte_vhost/fd_man.c:324:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
>   write(fdset->u.writefd, "1", 1);
>   ^
> 
> Reported-by: Andrew Rybchenko <arybchenko@solarflare.com>
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Squashed into relevant commit [1] in next-net, thanks.

(comment s/read()/write()/ fixed while applying)

[1]
7b23d25feb92 ("vhost: add pipe event for optimizing negotiating")
  

Patch

diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
index ca1ba2622..1f9e22f96 100644
--- a/lib/librte_vhost/fd_man.c
+++ b/lib/librte_vhost/fd_man.c
@@ -281,7 +281,13 @@  fdset_pipe_read_cb(int readfd, void *dat __rte_unused,
 		   int *remove __rte_unused)
 {
 	char charbuf[16];
-	read(readfd, charbuf, sizeof(charbuf));
+	int r = read(readfd, charbuf, sizeof(charbuf));
+	/*
+	 * Just an optimization, we don't care if read() failed
+	 * so ignore explicitly its return value to make the
+	 * compiler happy
+	 */
+	RTE_SET_USED(r);
 }
 
 void
@@ -321,5 +327,12 @@  fdset_pipe_init(struct fdset *fdset)
 void
 fdset_pipe_notify(struct fdset *fdset)
 {
-	write(fdset->u.writefd, "1", 1);
+	int r = write(fdset->u.writefd, "1", 1);
+	/*
+	 * Just an optimization, we don't care if read() failed
+	 * so ignore explicitly its return value to make the
+	 * compiler happy
+	 */
+	RTE_SET_USED(r);
+
 }