diff mbox

linux-generic: pktio: avoid coverity issues by adding explicit cast

Message ID 1459027277-6414-1-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer March 26, 2016, 9:21 p.m. UTC
Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2138 by adding an
explicit cast to odp_pktio_capability(). This routine cannot return a
bad RC since the error condition is already guarded earlier in the code,
however coverity doesn't see this.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 platform/linux-generic/odp_packet_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Maxim Uvarov April 1, 2016, 4:02 p.m. UTC | #1
On 03/27/16 00:21, Bill Fischofer wrote:
> Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2138 by adding an
> explicit cast to odp_pktio_capability(). This routine cannot return a
> bad RC since the error condition is already guarded earlier in the code,
> however coverity doesn't see this.
>
> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
> ---
>   platform/linux-generic/odp_packet_io.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
> index 9192be2..dfeeeaf 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -1059,7 +1059,7 @@ int odp_pktin_queue_config(odp_pktio_t pktio,
>   		return -1;
>   	}
>   
> -	odp_pktio_capability(pktio, &capa);
> +	(void)odp_pktio_capability(pktio, &capa);
>   
>   	if (num_queues > capa.max_input_queues) {

if call fails then what value will be in capa.max_input_queues ?
I think you can not ignore return code here.


>   		ODP_DBG("pktio %s: too many input queues\n", entry->s.name);
> @@ -1172,7 +1172,7 @@ int odp_pktout_queue_config(odp_pktio_t pktio,
>   		return -1;
>   	}
>   
> -	odp_pktio_capability(pktio, &capa);
> +	(void)odp_pktio_capability(pktio, &capa);
>   
>   	if (num_queues > capa.max_output_queues) {
>   		ODP_DBG("pktio %s: too many output queues\n", entry->s.name);
Same thing here.

Maxim.
Bill Fischofer April 3, 2016, 12:38 p.m. UTC | #2
On Fri, Apr 1, 2016 at 11:02 AM, Maxim Uvarov <maxim.uvarov@linaro.org>
wrote:

> On 03/27/16 00:21, Bill Fischofer wrote:

>

>> Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2138 by adding an

>> explicit cast to odp_pktio_capability(). This routine cannot return a

>> bad RC since the error condition is already guarded earlier in the code,

>> however coverity doesn't see this.

>>

>> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

>> ---

>>   platform/linux-generic/odp_packet_io.c | 4 ++--

>>   1 file changed, 2 insertions(+), 2 deletions(-)

>>

>> diff --git a/platform/linux-generic/odp_packet_io.c

>> b/platform/linux-generic/odp_packet_io.c

>> index 9192be2..dfeeeaf 100644

>> --- a/platform/linux-generic/odp_packet_io.c

>> +++ b/platform/linux-generic/odp_packet_io.c

>> @@ -1059,7 +1059,7 @@ int odp_pktin_queue_config(odp_pktio_t pktio,

>>                 return -1;

>>         }

>>   -     odp_pktio_capability(pktio, &capa);

>> +       (void)odp_pktio_capability(pktio, &capa);

>>         if (num_queues > capa.max_input_queues) {

>>

>

> if call fails then what value will be in capa.max_input_queues ?

> I think you can not ignore return code here.

>

>

The call cannot fail in this case because the code is guarded by , but
coverity doesn't see this. The cast simply let's coverity know that we're
ignoring the return code intentionally.

The guard is earlier in the code:

entry = get_pktio_entry(pktio);
if (entry == NULL) {
ODP_DBG("pktio entry %d does not exist\n", pktio);
return -1;
}

The only way odp_pktio_capability() fails is if the PktIO doesn't exist.


>

>                 ODP_DBG("pktio %s: too many input queues\n", entry->s.name

>> );

>> @@ -1172,7 +1172,7 @@ int odp_pktout_queue_config(odp_pktio_t pktio,

>>                 return -1;

>>         }

>>   -     odp_pktio_capability(pktio, &capa);

>> +       (void)odp_pktio_capability(pktio, &capa);

>>         if (num_queues > capa.max_output_queues) {

>>                 ODP_DBG("pktio %s: too many output queues\n", entry->

>> s.name);

>>

> Same thing here.

>

> Maxim.

> _______________________________________________

> lng-odp mailing list

> lng-odp@lists.linaro.org

> https://lists.linaro.org/mailman/listinfo/lng-odp

>
Maxim Uvarov April 4, 2016, 6:13 a.m. UTC | #3
On 04/03/16 15:38, Bill Fischofer wrote:
>
>
> On Fri, Apr 1, 2016 at 11:02 AM, Maxim Uvarov <maxim.uvarov@linaro.org 
> <mailto:maxim.uvarov@linaro.org>> wrote:
>
>     On 03/27/16 00:21, Bill Fischofer wrote:
>
>         Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2138 by
>         adding an
>         explicit cast to odp_pktio_capability(). This routine cannot
>         return a
>         bad RC since the error condition is already guarded earlier in
>         the code,
>         however coverity doesn't see this.
>
>         Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org
>         <mailto:bill.fischofer@linaro.org>>
>         ---
>           platform/linux-generic/odp_packet_io.c | 4 ++--
>           1 file changed, 2 insertions(+), 2 deletions(-)
>
>         diff --git a/platform/linux-generic/odp_packet_io.c
>         b/platform/linux-generic/odp_packet_io.c
>         index 9192be2..dfeeeaf 100644
>         --- a/platform/linux-generic/odp_packet_io.c
>         +++ b/platform/linux-generic/odp_packet_io.c
>         @@ -1059,7 +1059,7 @@ int odp_pktin_queue_config(odp_pktio_t
>         pktio,
>                         return -1;
>                 }
>           -     odp_pktio_capability(pktio, &capa);
>         +       (void)odp_pktio_capability(pktio, &capa);
>                 if (num_queues > capa.max_input_queues) {
>
>
>     if call fails then what value will be in capa.max_input_queues ?
>     I think you can not ignore return code here.
>
>
> The call cannot fail in this case because the code is guarded by , but 
> coverity doesn't see this. The cast simply let's coverity know that 
> we're ignoring the return code intentionally.
>
> The guard is earlier in the code:
>
> entry = get_pktio_entry(pktio);
> if (entry == NULL) {
> ODP_DBG("pktio entry %d does not exist\n", pktio);
> return -1;
> }
>
> The only way odp_pktio_capability() fails is if the PktIO doesn't exist.

if you refer to current implementation you are right. But in somebody 
will inherit that call from linux-generic and use his own 
odp_pktio_caps() call that here might be a problem. I think Coverity is 
right here said to not relay on internal checks for non void
functions.

Maxim.
>
>
>                       ODP_DBG("pktio %s: too many input queues\n",
>         entry->s.name <http://s.name>);
>         @@ -1172,7 +1172,7 @@ int odp_pktout_queue_config(odp_pktio_t
>         pktio,
>                         return -1;
>                 }
>           -     odp_pktio_capability(pktio, &capa);
>         +       (void)odp_pktio_capability(pktio, &capa);
>                 if (num_queues > capa.max_output_queues) {
>                         ODP_DBG("pktio %s: too many output queues\n",
>         entry->s.name <http://s.name>);
>
>     Same thing here.
>
>     Maxim.
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
Bill Fischofer April 4, 2016, 11:43 a.m. UTC | #4
Added to today's ARCH call to discuss this.

On Mon, Apr 4, 2016 at 1:13 AM, Maxim Uvarov <maxim.uvarov@linaro.org>
wrote:

> On 04/03/16 15:38, Bill Fischofer wrote:

>

>>

>>

>> On Fri, Apr 1, 2016 at 11:02 AM, Maxim Uvarov <maxim.uvarov@linaro.org

>> <mailto:maxim.uvarov@linaro.org>> wrote:

>>

>>     On 03/27/16 00:21, Bill Fischofer wrote:

>>

>>         Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2138 by

>>         adding an

>>         explicit cast to odp_pktio_capability(). This routine cannot

>>         return a

>>         bad RC since the error condition is already guarded earlier in

>>         the code,

>>         however coverity doesn't see this.

>>

>>         Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org

>>         <mailto:bill.fischofer@linaro.org>>

>>         ---

>>           platform/linux-generic/odp_packet_io.c | 4 ++--

>>           1 file changed, 2 insertions(+), 2 deletions(-)

>>

>>         diff --git a/platform/linux-generic/odp_packet_io.c

>>         b/platform/linux-generic/odp_packet_io.c

>>         index 9192be2..dfeeeaf 100644

>>         --- a/platform/linux-generic/odp_packet_io.c

>>         +++ b/platform/linux-generic/odp_packet_io.c

>>         @@ -1059,7 +1059,7 @@ int odp_pktin_queue_config(odp_pktio_t

>>         pktio,

>>                         return -1;

>>                 }

>>           -     odp_pktio_capability(pktio, &capa);

>>         +       (void)odp_pktio_capability(pktio, &capa);

>>                 if (num_queues > capa.max_input_queues) {

>>

>>

>>     if call fails then what value will be in capa.max_input_queues ?

>>     I think you can not ignore return code here.

>>

>>

>> The call cannot fail in this case because the code is guarded by , but

>> coverity doesn't see this. The cast simply let's coverity know that we're

>> ignoring the return code intentionally.

>>

>> The guard is earlier in the code:

>>

>> entry = get_pktio_entry(pktio);

>> if (entry == NULL) {

>> ODP_DBG("pktio entry %d does not exist\n", pktio);

>> return -1;

>> }

>>

>> The only way odp_pktio_capability() fails is if the PktIO doesn't exist.

>>

>

> if you refer to current implementation you are right. But in somebody will

> inherit that call from linux-generic and use his own odp_pktio_caps() call

> that here might be a problem. I think Coverity is right here said to not

> relay on internal checks for non void

> functions.

>

> Maxim.

>

>>

>>

>>                       ODP_DBG("pktio %s: too many input queues\n",

>>         entry->s.name <http://s.name>);

>>         @@ -1172,7 +1172,7 @@ int odp_pktout_queue_config(odp_pktio_t

>>         pktio,

>>                         return -1;

>>                 }

>>           -     odp_pktio_capability(pktio, &capa);

>>         +       (void)odp_pktio_capability(pktio, &capa);

>>                 if (num_queues > capa.max_output_queues) {

>>                         ODP_DBG("pktio %s: too many output queues\n",

>>         entry->s.name <http://s.name>);

>>

>>     Same thing here.

>>

>>     Maxim.

>>     _______________________________________________

>>     lng-odp mailing list

>>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>

>>     https://lists.linaro.org/mailman/listinfo/lng-odp

>>

>>

>>

>
diff mbox

Patch

diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 9192be2..dfeeeaf 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -1059,7 +1059,7 @@  int odp_pktin_queue_config(odp_pktio_t pktio,
 		return -1;
 	}
 
-	odp_pktio_capability(pktio, &capa);
+	(void)odp_pktio_capability(pktio, &capa);
 
 	if (num_queues > capa.max_input_queues) {
 		ODP_DBG("pktio %s: too many input queues\n", entry->s.name);
@@ -1172,7 +1172,7 @@  int odp_pktout_queue_config(odp_pktio_t pktio,
 		return -1;
 	}
 
-	odp_pktio_capability(pktio, &capa);
+	(void)odp_pktio_capability(pktio, &capa);
 
 	if (num_queues > capa.max_output_queues) {
 		ODP_DBG("pktio %s: too many output queues\n", entry->s.name);