Skip to contentSkip to conversation

rhashtable: Add nested tables

bug report Dan Carpenter 3 participants 3 messages Feb 16, 2017 – Feb 27, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

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	

regards,
dan carpenter

maintainer
#1 lore raw
Quoted 16 lines · Dan Carpenter

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.

Quoted 8 lines
   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.

---

 lib/rhashtable.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/rhashtable.c +1 -3
index 172454e..fac1a78 100644
@@ -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);
 }
 
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#2 lore raw

From: Herbert Xu <[email protected]>
Date: Sat, 25 Feb 2017 22:38:11 +0800

Quoted 9 lines

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.

Also applied, thanks Herbert.