Skip to contentSkip to conversation

btrfs: remove unneeded check for btrfs_free_space_info in insert_into_bitmap()

PATCH In review Johannes Thumshirn 2 participants 2 messages Nov 5, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: remove unneeded check for btrfs_free_space_info in insert_into_bitmap()

The only caller for insert_into_bitmap() is __btrfs_add_free_space() and it takes care that the btrfs_free_space_info pointer passed to insert_into_bitmap() is allocated.

Inside insert_into_bitmap() we're not freeing or NULLing this pointer anywhere, so checking if it is pre-allocated inside 'new_bitmap' label is pointless, so remove this check.

---
 fs/btrfs/free-space-cache.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
fs/btrfs/free-space-cache.c +5 -18
index 279c41c4ba50..02f680be8999 100644
@@ -2121,7 +2121,7 @@ static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl,
 		goto again;
 
 new_bitmap:
-	if (info && info->bitmap) {
+	if (info->bitmap) {
 		add_new_bitmap(ctl, info, offset);
 		added = 1;
 		info = NULL;
@@ -2129,17 +2129,6 @@ static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl,
 	} else {
 		spin_unlock(&ctl->tree_lock);
 
-		/* no pre-allocated info, allocate a new one */
-		if (!info) {
-			info = kmem_cache_zalloc(btrfs_free_space_cachep,
-						 GFP_NOFS);
-			if (!info) {
-				spin_lock(&ctl->tree_lock);
-				ret = -ENOMEM;
-				goto out;
-			}
-		}
-
 		/* allocate the bitmap */
 		info->bitmap = kmem_cache_zalloc(btrfs_free_space_bitmap_cachep,
 						 GFP_NOFS);
@@ -2152,12 +2141,10 @@ static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl,
 	}
 
 out:
-	if (info) {
-		if (info->bitmap)
-			kmem_cache_free(btrfs_free_space_bitmap_cachep,
-					info->bitmap);
-		kmem_cache_free(btrfs_free_space_cachep, info);
-	}
+	if (info->bitmap)
+		kmem_cache_free(btrfs_free_space_bitmap_cachep,
+				info->bitmap);
+	kmem_cache_free(btrfs_free_space_cachep, info);
 
 	return ret;
 }
Signature · 1 line
2.16.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Johannes Thumshirn

The only caller for insert_into_bitmap() is __btrfs_add_free_space() and it takes care that the btrfs_free_space_info pointer passed to insert_into_bitmap() is allocated.

Inside insert_into_bitmap() we're not freeing or NULLing this pointer anywhere, so checking if it is pre-allocated inside 'new_bitmap' label is pointless, so remove this check.