2021-01-26 05:23:12

by Abaci Team

[permalink] [raw]
Subject: [PATCH 4/4] cxgb4: remove redundant NULL check

Fix below warnings reported by coccicheck:
./drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c:533:2-8: WARNING:
NULL check before some freeing functions is not needed.

Reported-by: Abaci Robot <[email protected]>
Signed-off-by: Yang Li <[email protected]>
---
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
index dede025..97a811f 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
@@ -525,12 +525,10 @@ struct cxgb4_tc_u32_table *cxgb4_init_tc_u32(struct adapter *adap)
for (i = 0; i < t->size; i++) {
struct cxgb4_link *link = &t->table[i];

- if (link->tid_map)
- kvfree(link->tid_map);
+ kvfree(link->tid_map);
}

- if (t)
- kvfree(t);
+ kvfree(t);

return NULL;
}
--
1.8.3.1


2021-01-27 21:06:33

by Raju Rangoju

[permalink] [raw]
Subject: Re: [PATCH 4/4] cxgb4: remove redundant NULL check

On Monday, January 01/25/21, 2021 at 17:47:25 +0800, Yang Li wrote:
> Fix below warnings reported by coccicheck:
> ./drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c:533:2-8: WARNING:
> NULL check before some freeing functions is not needed.
>
> Reported-by: Abaci Robot <[email protected]>
> Signed-off-by: Yang Li <[email protected]>
> ---
> drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
> index dede025..97a811f 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
> @@ -525,12 +525,10 @@ struct cxgb4_tc_u32_table *cxgb4_init_tc_u32(struct adapter *adap)
> for (i = 0; i < t->size; i++) {
> struct cxgb4_link *link = &t->table[i];
>
> - if (link->tid_map)
> - kvfree(link->tid_map);

This patch is wrong. NAK.

What if the call to link->tid_map = kvcalloc() fails above? it still goes ahead
and calls kvfree(link->tid_map), which is wrong.


> + kvfree(link->tid_map);
> }
>
> - if (t)
> - kvfree(t);
> + kvfree(t);
>
> return NULL;
> }
> --
> 1.8.3.1
>