Linux-BTRFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] btrfs: remove unneeded check for btrfs_free_space_info in insert_into_bitmap()
@ 2019-11-05 13:51 Johannes Thumshirn
  2019-11-05 17:08 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Thumshirn @ 2019-11-05 13:51 UTC (permalink / raw)
  To: David Sterba; +Cc: Linux BTRFS Mailinglist, 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.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 fs/btrfs/free-space-cache.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 279c41c4ba50..02f680be8999 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -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;
 }
-- 
2.16.4


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

* Re: [PATCH] btrfs: remove unneeded check for btrfs_free_space_info in insert_into_bitmap()
  2019-11-05 13:51 [PATCH] btrfs: remove unneeded check for btrfs_free_space_info in insert_into_bitmap() Johannes Thumshirn
@ 2019-11-05 17:08 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2019-11-05 17:08 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: David Sterba, Linux BTRFS Mailinglist

On Tue, Nov 05, 2019 at 02:51:27PM +0100, Johannes Thumshirn wrote:
> 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.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>

Reviewed-by: David Sterba <dsterba@suse.com>

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05 13:51 [PATCH] btrfs: remove unneeded check for btrfs_free_space_info in insert_into_bitmap() Johannes Thumshirn
2019-11-05 17:08 ` David Sterba

Linux-BTRFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-btrfs/0 linux-btrfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-btrfs linux-btrfs/ https://lore.kernel.org/linux-btrfs \
		linux-btrfs@vger.kernel.org
	public-inbox-index linux-btrfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-btrfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git