Linux-ext4 Archive mirror
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Li zeming <zeming@nfschina.com>
Cc: Theodore Ts'o <tytso@mit.edu>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ext4: extents: Remove unnecessary ‘NULL’ values from ablocks
Date: Mon, 8 Apr 2024 14:51:23 -0600	[thread overview]
Message-ID: <9859512C-90E0-42AE-BF14-71E4D28B7A1D@dilger.ca> (raw)
In-Reply-To: <20240402024804.29411-1-zeming@nfschina.com>

[-- Attachment #1: Type: text/plain, Size: 2010 bytes --]

On Apr 1, 2024, at 8:48 PM, Li zeming <zeming@nfschina.com> wrote:
> 
> ablocks is assigned first, so it does not need to initialize the
> assignment.

While it is true that "ablocks" is currently set before use,
this is happening a long way away from the variable declaration
and also "ablocks" is used after the "cleanup:" label error case:

cleanup:
        if (bh) {
                if (buffer_locked(bh))
                        unlock_buffer(bh);
                brelse(bh);
        }

        if (err) {
                /* free all allocated blocks in error case */
                for (i = 0; i < depth; i++) {
                        if (!ablocks[i])
                                continue;
                        ext4_free_blocks(handle, inode, NULL, ablocks[i], 1,
                                         EXT4_FREE_BLOCKS_METADATA);
                }
        }
        kfree(ablocks);

So there is definitely a risk that a code change in the future
would introduce hard-to-debug problems, crashes, or even just
spurious static code analysis warnings.  My recommendation would
be to keep this 1-cycle local variable initialization in place
rather than spend hours or days trying to debug and fix a crash
here in the future.

Cheers, Andreas

> 
> Signed-off-by: Li zeming <zeming@nfschina.com>
> ---
> fs/ext4/extents.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 4ab96f01a6f31..caace8c3fd3c1 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -1061,7 +1061,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
> 	int i = at, k, m, a;
> 	ext4_fsblk_t newblock, oldblock;
> 	__le32 border;
> -	ext4_fsblk_t *ablocks = NULL; /* array of allocated blocks */
> +	ext4_fsblk_t *ablocks; /* array of allocated blocks */
> 	gfp_t gfp_flags = GFP_NOFS;
> 	int err = 0;
> 	size_t ext_size = 0;
> --
> 2.18.2
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

      parent reply	other threads:[~2024-04-08 20:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02  2:48 [PATCH] ext4: extents: Remove unnecessary ‘NULL’ values from ablocks Li zeming
2024-04-02  3:55 ` Theodore Ts'o
2024-04-08 20:51 ` Andreas Dilger [this message]

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=9859512C-90E0-42AE-BF14-71E4D28B7A1D@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=zeming@nfschina.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).