netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [bug report] rhashtable: Add nested tables
       [not found] <20170216121703.GA26276@mwanda>
@ 2017-02-25 14:38 ` Herbert Xu
  2017-02-27  2:34   ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Herbert Xu @ 2017-02-25 14:38 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: kernel-janitors, netdev, Thomas Graf

On Thu, Feb 16, 2017 at 03:17:03PM +0300, Dan Carpenter wrote:
> Hello Herbert Xu,
> 
> This is a semi-automatic email about new static checker warnings.
> 
> The patch 40137906c5f5: "rhashtable: Add nested tables" from Feb 11, 
> 2017, leads to the following Smatch complaint:
> 
> lib/rhashtable.c:149 bucket_table_free()
> 	 warn: variable dereferenced before check 'tbl' (see line 146)
> 
> lib/rhashtable.c
>    145	{
>    146		if (tbl->nest)
>                     ^^^^^^^^^
> New unchecked dereference.
> 
>    147			nested_bucket_table_free(tbl);
>    148	
>    149		if (tbl)
>                     ^^^
> Old code checked for NULL.
> 
>    150			kvfree(tbl->locks);
>    151	

Thanks for catching this.  I checked all the callers and none
of them can provide a NULL pointer so let's just kill the check.

---8<---
Subject: rhashtable: Fix use before NULL check in bucket_table_free

Dan Carpenter reported a use before NULL check bug in the function
bucket_table_free.  In fact we don't need the NULL check at all as
no caller can provide a NULL argument.  So this patch fixes this by
simply removing it.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 lib/rhashtable.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 172454e..fac1a78 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -146,9 +146,7 @@ static void bucket_table_free(const struct bucket_table *tbl)
 	if (tbl->nest)
 		nested_bucket_table_free(tbl);
 
-	if (tbl)
-		kvfree(tbl->locks);
-
+	kvfree(tbl->locks);
 	kvfree(tbl);
 }
 
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [bug report] rhashtable: Add nested tables
  2017-02-25 14:38 ` [bug report] rhashtable: Add nested tables Herbert Xu
@ 2017-02-27  2:34   ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2017-02-27  2:34 UTC (permalink / raw)
  To: herbert; +Cc: dan.carpenter, kernel-janitors, netdev, tgraf

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Sat, 25 Feb 2017 22:38:11 +0800

> Subject: rhashtable: Fix use before NULL check in bucket_table_free
> 
> Dan Carpenter reported a use before NULL check bug in the function
> bucket_table_free.  In fact we don't need the NULL check at all as
> no caller can provide a NULL argument.  So this patch fixes this by
> simply removing it.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Also applied, thanks Herbert.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-27  2:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20170216121703.GA26276@mwanda>
2017-02-25 14:38 ` [bug report] rhashtable: Add nested tables Herbert Xu
2017-02-27  2:34   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).