2019-05-05 21:39:39

by Colin King

[permalink] [raw]
Subject: [PATCH][next] net: mvpp2: cls: fix less than zero check on a u32 variable

From: Colin Ian King <[email protected]>

The signed return from the call to mvpp2_cls_c2_port_flow_index is being
assigned to the u32 variable c2.index and then checked for a negative
error condition which is always going to be false. Fix this by assigning
the return to the int variable index and checking this instead.

Addresses-Coverity: ("Unsigned compared against 0")
Fixes: 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")
Signed-off-by: Colin Ian King <[email protected]>
---
drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c
index 4989fb13244f..c10bc257f571 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c
@@ -1029,12 +1029,14 @@ static int mvpp2_port_c2_tcam_rule_add(struct mvpp2_port *port,
struct flow_action_entry *act;
struct mvpp2_cls_c2_entry c2;
u8 qh, ql, pmap;
+ int index;

memset(&c2, 0, sizeof(c2));

- c2.index = mvpp2_cls_c2_port_flow_index(port, rule->loc);
- if (c2.index < 0)
+ index = mvpp2_cls_c2_port_flow_index(port, rule->loc);
+ if (index < 0)
return -EINVAL;
+ c2.index = index;

act = &rule->flow->action.entries[0];

--
2.20.1


2019-05-06 07:43:14

by Maxime Chevallier

[permalink] [raw]
Subject: Re: [PATCH][next] net: mvpp2: cls: fix less than zero check on a u32 variable

Hi Colin,

On Sun, 5 May 2019 22:38:14 +0100
Colin King <[email protected]> wrote:

>From: Colin Ian King <[email protected]>
>
>The signed return from the call to mvpp2_cls_c2_port_flow_index is being
>assigned to the u32 variable c2.index and then checked for a negative
>error condition which is always going to be false. Fix this by assigning
>the return to the int variable index and checking this instead.
>
>Addresses-Coverity: ("Unsigned compared against 0")
>Fixes: 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")
>Signed-off-by: Colin Ian King <[email protected]>
>---
> drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c
>index 4989fb13244f..c10bc257f571 100644
>--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c
>+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c
>@@ -1029,12 +1029,14 @@ static int mvpp2_port_c2_tcam_rule_add(struct mvpp2_port *port,
> struct flow_action_entry *act;
> struct mvpp2_cls_c2_entry c2;
> u8 qh, ql, pmap;
>+ int index;
>
> memset(&c2, 0, sizeof(c2));
>
>- c2.index = mvpp2_cls_c2_port_flow_index(port, rule->loc);
>- if (c2.index < 0)
>+ index = mvpp2_cls_c2_port_flow_index(port, rule->loc);
>+ if (index < 0)
> return -EINVAL;
>+ c2.index = index;
>
> act = &rule->flow->action.entries[0];
>

Thanks for the fix, my bad.

Reviewed-by: Maxime Chevallier <[email protected]>

Maxime

2019-05-07 19:17:23

by David Miller

[permalink] [raw]
Subject: Re: [PATCH][next] net: mvpp2: cls: fix less than zero check on a u32 variable

From: Colin King <[email protected]>
Date: Sun, 5 May 2019 22:38:14 +0100

> From: Colin Ian King <[email protected]>
>
> The signed return from the call to mvpp2_cls_c2_port_flow_index is being
> assigned to the u32 variable c2.index and then checked for a negative
> error condition which is always going to be false. Fix this by assigning
> the return to the int variable index and checking this instead.
>
> Addresses-Coverity: ("Unsigned compared against 0")
> Fixes: 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")
> Signed-off-by: Colin Ian King <[email protected]>

Applied.