Skip to contentSkip to conversation

fs: btrfs: free-space-cache.c: remove two unnecessary checks before calling kfree()

PATCH In review Bas Peters 3 participants 6 messages Feb 11, 2015

Subsystems (2)
lore
Share & tools
lore

Bas Peters

author
#0 lore raw

PATCH 1/1 fs: btrfs: free-space-cache.c: remove two unnecessary checks before calling kfree()

kfree checks whether the pointer it is passed is NULL. The two foregoing checks are therefore unnecessary.

This issue was detected using Coccinelle.

---
 fs/btrfs/free-space-cache.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/free-space-cache.c +2 -4
index d6c03f7..7d2d817 100644
@@ -1976,8 +1976,7 @@ new_bitmap:
 
 out:
 	if (info) {
-		if (info->bitmap)
-			kfree(info->bitmap);
+		kfree(info->bitmap);
 		kmem_cache_free(btrfs_free_space_cachep, info);
 	}
 
@@ -3427,8 +3426,7 @@ again:
 
 	if (info)
 		kmem_cache_free(btrfs_free_space_cachep, info);
-	if (map)
-		kfree(map);
+	kfree(map);
 	return 0;
 }
 
Signature · 1 line
2.1.0
#1 lore raw
Quoted 25 lines · Bas Peters

kfree checks whether the pointer it is passed is NULL. The two foregoing checks are therefore unnecessary.

This issue was detected using Coccinelle.

---
 fs/btrfs/free-space-cache.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/free-space-cache.c +1 -2
index d6c03f7..7d2d817 100644
@@ -1976,8 +1976,7 @@ new_bitmap:
 
 out:
 	if (info) {
-		if (info->bitmap)
-			kfree(info->bitmap);
+		kfree(info->bitmap);
 		kmem_cache_free(btrfs_free_space_cachep, info);
 	}
 

fs/btrfs/free-space-cache.c again: · line 3429

Quoted 6 lines
fs/btrfs/free-space-cache.c +1 -2
@@ -3427,8 +3426,7 @@ again:
 
 	if (info)
 		kmem_cache_free(btrfs_free_space_cachep, info);
-	if (map)
-		kfree(map);
+	kfree(map);

A certain lack of parallelism arises in the latter case.

julia

Quoted 11 lines
fs/btrfs/free-space-cache.c +0 -1
 	return 0;
 }
 
--

2.1.0

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Bas Peters
Quoted 4 lines

kfree checks whether the pointer it is passed is NULL. The two foregoing checks are therefore unnecessary.

This issue was detected using Coccinelle.

Would you like to integrate my update suggestion "btrfs: Deletion of unnecessary checks before six function calls"?
https://lkml.org/lkml/2014/10/31/606
http://article.gmane.org/gmane.linux.kernel/1818924
https://systeme.lip6.fr/pipermail/cocci/2014-October/001321.html

Regards,
Markus

author
#3 lore raw

2015-02-11 12:30 GMT+01:00 SF Markus Elfring <[email protected]>:

Quoted 10 lines
Quoted 4 lines

kfree checks whether the pointer it is passed is NULL. The two foregoing checks are therefore unnecessary.

This issue was detected using Coccinelle.

Would you like to integrate my update suggestion "btrfs: Deletion of unnecessary checks before six function calls"?
https://lkml.org/lkml/2014/10/31/606
http://article.gmane.org/gmane.linux.kernel/1818924
https://systeme.lip6.fr/pipermail/cocci/2014-October/001321.html

Oh, I see you already made the exact same change.
I'll just drop my patch in that case.

Quoted 4 lines

Regards,
Markus

author
#5 lore raw

Markus,

2015-02-11 13:18 GMT+01:00 SF Markus Elfring <[email protected]>:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

https://lkml.org/lkml/2014/10/31/606
http://article.gmane.org/gmane.linux.kernel/1818924
https://systeme.lip6.fr/pipermail/cocci/2014-October/001321.html

Oh, I see you already made the exact same change.

Would you like to add any tags to my update suggestion?

No, it's fine, I should've checked before submitting the patch.

Quoted 3 lines

Regards,
Markus