diff mbox

[PATCHv4] linux-generic: pktio: avoid coverity issues by adding explicit rc check

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

Commit Message

Bill Fischofer April 4, 2016, 2:42 p.m. UTC
Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2138 by adding an
explicit rc check for odp_pktio_capability().

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

Comments

Maxim Uvarov April 4, 2016, 3:26 p.m. UTC | #1
On 04/04/16 17:42, Bill Fischofer wrote:
> Resolve bug https://bugs.linaro.org/show_bug.cgi?id=2138 by adding an
> explicit rc check for odp_pktio_capability().
>
> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
> ---
>   platform/linux-generic/odp_packet_io.c | 24 ++++++++++++++++++------
>   1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
> index 9192be2..b0f3423 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -1027,6 +1027,7 @@ int odp_pktin_queue_config(odp_pktio_t pktio,
>   	odp_pktio_capability_t capa;
>   	unsigned num_queues;
>   	unsigned i;
> +	int rc;
>   	odp_queue_t queue;
>   	odp_pktin_queue_param_t default_param;
>   
> @@ -1059,10 +1060,15 @@ int odp_pktin_queue_config(odp_pktio_t pktio,
>   		return -1;
>   	}
>   
> -	odp_pktio_capability(pktio, &capa);
> +	rc = odp_pktio_capability(pktio, &capa);
>   
> -	if (num_queues > capa.max_input_queues) {
> -		ODP_DBG("pktio %s: too many input queues\n", entry->s.name);
> +	if (rc != 0 || num_queues > capa.max_input_queues) {
> +		if (rc != 0)
> +			ODP_DBG("pktio %s: unable to read capabilities\n",
> +				entry->s.name);
> +		else
> +			ODP_DBG("pktio %s: too many input queues\n",
> +				entry->s.name);
>   		return -1;

it's that match simple to read?:

rc = odp_pktio_capability(pktio, &capa);
if (rc) {
     ODP_DBG("pktio %s: unable to read capabilities\n",
                 entry->s.name);
     return -1;
}

if (num_queues > capa.max_input_queues) {
         ODP_DBG("pktio %s: unable to read capabilities\n", + 
entry->s.name);
         return -1;
}

>   	}
>   
> @@ -1135,6 +1141,7 @@ int odp_pktout_queue_config(odp_pktio_t pktio,
>   	odp_pktio_capability_t capa;
>   	unsigned num_queues;
>   	unsigned i;
> +	int rc;
>   	odp_pktout_queue_param_t default_param;
>   
>   	if (param == NULL) {
> @@ -1172,10 +1179,15 @@ int odp_pktout_queue_config(odp_pktio_t pktio,
>   		return -1;
>   	}
>   
> -	odp_pktio_capability(pktio, &capa);
> +	rc = odp_pktio_capability(pktio, &capa);
>   
> -	if (num_queues > capa.max_output_queues) {
> -		ODP_DBG("pktio %s: too many output queues\n", entry->s.name);
> +	if (rc != 0 || num_queues > capa.max_output_queues) {
> +		if (rc != 0)
> +			ODP_DBG("pktio %s: unable to read capabilities\n",
> +				entry->s.name);
> +		else
> +			ODP_DBG("pktio %s: too many output queues\n",
> +				entry->s.name);
>   		return -1;
>   	}
>
Bill Fischofer April 4, 2016, 4:14 p.m. UTC | #2
OK, v5 sent with that suggested change.

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

> On 04/04/16 17:42, Bill Fischofer wrote:

>

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

>> explicit rc check for odp_pktio_capability().

>>

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

>> ---

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

>>   1 file changed, 18 insertions(+), 6 deletions(-)

>>

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

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

>> index 9192be2..b0f3423 100644

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

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

>> @@ -1027,6 +1027,7 @@ int odp_pktin_queue_config(odp_pktio_t pktio,

>>         odp_pktio_capability_t capa;

>>         unsigned num_queues;

>>         unsigned i;

>> +       int rc;

>>         odp_queue_t queue;

>>         odp_pktin_queue_param_t default_param;

>>   @@ -1059,10 +1060,15 @@ int odp_pktin_queue_config(odp_pktio_t pktio,

>>                 return -1;

>>         }

>>   -     odp_pktio_capability(pktio, &capa);

>> +       rc = odp_pktio_capability(pktio, &capa);

>>   -     if (num_queues > capa.max_input_queues) {

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

>> s.name);

>> +       if (rc != 0 || num_queues > capa.max_input_queues) {

>> +               if (rc != 0)

>> +                       ODP_DBG("pktio %s: unable to read capabilities\n",

>> +                               entry->s.name);

>> +               else

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

>> +                               entry->s.name);

>>                 return -1;

>>

>

> it's that match simple to read?:

>

> rc = odp_pktio_capability(pktio, &capa);

> if (rc) {

>     ODP_DBG("pktio %s: unable to read capabilities\n",

>                 entry->s.name);

>     return -1;

> }

>

> if (num_queues > capa.max_input_queues) {

>         ODP_DBG("pktio %s: unable to read capabilities\n", + entry->s.name

> );

>         return -1;

> }

>

>         }

>>   @@ -1135,6 +1141,7 @@ int odp_pktout_queue_config(odp_pktio_t pktio,

>>         odp_pktio_capability_t capa;

>>         unsigned num_queues;

>>         unsigned i;

>> +       int rc;

>>         odp_pktout_queue_param_t default_param;

>>         if (param == NULL) {

>> @@ -1172,10 +1179,15 @@ int odp_pktout_queue_config(odp_pktio_t pktio,

>>                 return -1;

>>         }

>>   -     odp_pktio_capability(pktio, &capa);

>> +       rc = odp_pktio_capability(pktio, &capa);

>>   -     if (num_queues > capa.max_output_queues) {

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

>> s.name);

>> +       if (rc != 0 || num_queues > capa.max_output_queues) {

>> +               if (rc != 0)

>> +                       ODP_DBG("pktio %s: unable to read capabilities\n",

>> +                               entry->s.name);

>> +               else

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

>> +                               entry->s.name);

>>                 return -1;

>>         }

>>

>>

>

> _______________________________________________

> lng-odp mailing list

> lng-odp@lists.linaro.org

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

>
Bill Fischofer April 14, 2016, 12:46 p.m. UTC | #3
ping.  v5 needs review.

On Mon, Apr 4, 2016 at 11:14 AM, Bill Fischofer <bill.fischofer@linaro.org>
wrote:

> OK, v5 sent with that suggested change.

>

> On Mon, Apr 4, 2016 at 10:26 AM, Maxim Uvarov <maxim.uvarov@linaro.org>

> wrote:

>

>> On 04/04/16 17:42, Bill Fischofer wrote:

>>

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

>>> explicit rc check for odp_pktio_capability().

>>>

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

>>> ---

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

>>>   1 file changed, 18 insertions(+), 6 deletions(-)

>>>

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

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

>>> index 9192be2..b0f3423 100644

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

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

>>> @@ -1027,6 +1027,7 @@ int odp_pktin_queue_config(odp_pktio_t pktio,

>>>         odp_pktio_capability_t capa;

>>>         unsigned num_queues;

>>>         unsigned i;

>>> +       int rc;

>>>         odp_queue_t queue;

>>>         odp_pktin_queue_param_t default_param;

>>>   @@ -1059,10 +1060,15 @@ int odp_pktin_queue_config(odp_pktio_t pktio,

>>>                 return -1;

>>>         }

>>>   -     odp_pktio_capability(pktio, &capa);

>>> +       rc = odp_pktio_capability(pktio, &capa);

>>>   -     if (num_queues > capa.max_input_queues) {

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

>>> s.name);

>>> +       if (rc != 0 || num_queues > capa.max_input_queues) {

>>> +               if (rc != 0)

>>> +                       ODP_DBG("pktio %s: unable to read

>>> capabilities\n",

>>> +                               entry->s.name);

>>> +               else

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

>>> +                               entry->s.name);

>>>                 return -1;

>>>

>>

>> it's that match simple to read?:

>>

>> rc = odp_pktio_capability(pktio, &capa);

>> if (rc) {

>>     ODP_DBG("pktio %s: unable to read capabilities\n",

>>                 entry->s.name);

>>     return -1;

>> }

>>

>> if (num_queues > capa.max_input_queues) {

>>         ODP_DBG("pktio %s: unable to read capabilities\n", + entry->

>> s.name);

>>         return -1;

>> }

>>

>>         }

>>>   @@ -1135,6 +1141,7 @@ int odp_pktout_queue_config(odp_pktio_t pktio,

>>>         odp_pktio_capability_t capa;

>>>         unsigned num_queues;

>>>         unsigned i;

>>> +       int rc;

>>>         odp_pktout_queue_param_t default_param;

>>>         if (param == NULL) {

>>> @@ -1172,10 +1179,15 @@ int odp_pktout_queue_config(odp_pktio_t pktio,

>>>                 return -1;

>>>         }

>>>   -     odp_pktio_capability(pktio, &capa);

>>> +       rc = odp_pktio_capability(pktio, &capa);

>>>   -     if (num_queues > capa.max_output_queues) {

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

>>> s.name);

>>> +       if (rc != 0 || num_queues > capa.max_output_queues) {

>>> +               if (rc != 0)

>>> +                       ODP_DBG("pktio %s: unable to read

>>> capabilities\n",

>>> +                               entry->s.name);

>>> +               else

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

>>> +                               entry->s.name);

>>>                 return -1;

>>>         }

>>>

>>>

>>

>> _______________________________________________

>> lng-odp mailing list

>> 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..b0f3423 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -1027,6 +1027,7 @@  int odp_pktin_queue_config(odp_pktio_t pktio,
 	odp_pktio_capability_t capa;
 	unsigned num_queues;
 	unsigned i;
+	int rc;
 	odp_queue_t queue;
 	odp_pktin_queue_param_t default_param;
 
@@ -1059,10 +1060,15 @@  int odp_pktin_queue_config(odp_pktio_t pktio,
 		return -1;
 	}
 
-	odp_pktio_capability(pktio, &capa);
+	rc = odp_pktio_capability(pktio, &capa);
 
-	if (num_queues > capa.max_input_queues) {
-		ODP_DBG("pktio %s: too many input queues\n", entry->s.name);
+	if (rc != 0 || num_queues > capa.max_input_queues) {
+		if (rc != 0)
+			ODP_DBG("pktio %s: unable to read capabilities\n",
+				entry->s.name);
+		else
+			ODP_DBG("pktio %s: too many input queues\n",
+				entry->s.name);
 		return -1;
 	}
 
@@ -1135,6 +1141,7 @@  int odp_pktout_queue_config(odp_pktio_t pktio,
 	odp_pktio_capability_t capa;
 	unsigned num_queues;
 	unsigned i;
+	int rc;
 	odp_pktout_queue_param_t default_param;
 
 	if (param == NULL) {
@@ -1172,10 +1179,15 @@  int odp_pktout_queue_config(odp_pktio_t pktio,
 		return -1;
 	}
 
-	odp_pktio_capability(pktio, &capa);
+	rc = odp_pktio_capability(pktio, &capa);
 
-	if (num_queues > capa.max_output_queues) {
-		ODP_DBG("pktio %s: too many output queues\n", entry->s.name);
+	if (rc != 0 || num_queues > capa.max_output_queues) {
+		if (rc != 0)
+			ODP_DBG("pktio %s: unable to read capabilities\n",
+				entry->s.name);
+		else
+			ODP_DBG("pktio %s: too many output queues\n",
+				entry->s.name);
 		return -1;
 	}