All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: Re: [PATCH] btrfs: Remove redundant code
Date: Wed, 12 Jul 2017 16:55:35 +0200	[thread overview]
Message-ID: <20170712145535.GE2866@twin.jikos.cz> (raw)
In-Reply-To: <1499841135-18251-1-git-send-email-nborisov@suse.com>

On Wed, Jul 12, 2017 at 09:32:15AM +0300, Nikolay Borisov wrote:
> insert_into_bitmap has only one caller which always allocates the info struct
> passed. As such remove the any NULL checks for info and also remove code
> to allocate info in case it was NULL.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>  fs/btrfs/free-space-cache.c | 13 +------------
>  1 file changed, 1 insertion(+), 12 deletions(-)
> 
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index c5e6180cdb8c..fd24fb99d6dc 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -2101,7 +2101,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;

What if we reach this point, go back to label "again:", come back to
this check again, then info would be NULL and dereferencing info->bitmap
would crash. Then the below code is still required.

> @@ -2109,17 +2109,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 = kzalloc(PAGE_SIZE, GFP_NOFS);
>  		spin_lock(&ctl->tree_lock);
> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-07-12 14:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12  6:32 [PATCH] btrfs: Remove redundant code Nikolay Borisov
2017-07-12 14:55 ` David Sterba [this message]
2022-09-18  7:26 [PATCH] btrfs: remove " flyingpeng(彭浩)
2022-09-23 14:56 Hao Peng
2022-10-07 16:32 ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170712145535.GE2866@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.