From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Allison Collins <allison.henderson@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/1] xfs: Fix Smatch warning in xfs_attr_node_get
Date: Tue, 28 Jul 2020 18:23:48 -0700 [thread overview]
Message-ID: <20200729012348.GD3151642@magnolia> (raw)
In-Reply-To: <20200729000853.10215-1-allison.henderson@oracle.com>
On Tue, Jul 28, 2020 at 05:08:53PM -0700, Allison Collins wrote:
> Fix warning: variable dereferenced before check 'state' in
> xfs_attr_node_get. If xfs_attr_node_hasname fails, it may return a null
> state. If state is null, do not derefrence it. Go straight to out.
>
> Signed-off-by: Allison Collins <allison.henderson@oracle.com>
> ---
> fs/xfs/libxfs/xfs_attr.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
> index e5ec9ed..90b7b24 100644
> --- a/fs/xfs/libxfs/xfs_attr.c
> +++ b/fs/xfs/libxfs/xfs_attr.c
> @@ -1409,6 +1409,9 @@ xfs_attr_node_get(
> * Search to see if name exists, and get back a pointer to it.
> */
> error = xfs_attr_node_hasname(args, &state);
> + if (!state)
> + goto out;
> +
> if (error != -EEXIST)
> goto out_release;
>
> @@ -1426,7 +1429,7 @@ xfs_attr_node_get(
I would've just changed the for loop to:
for (i = 0; state && i < state->path.active; i++) {
Since that way we'd know that the error-out path always does the right
thing wrt any resources that could have been allocated.
--D
> xfs_trans_brelse(args->trans, state->path.blk[i].bp);
> state->path.blk[i].bp = NULL;
> }
> -
> +out:
> if (state)
> xfs_da_state_free(state);
> return error;
> --
> 2.7.4
>
next prev parent reply other threads:[~2020-07-29 1:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 0:08 [PATCH 1/1] xfs: Fix Smatch warning in xfs_attr_node_get Allison Collins
2020-07-29 1:23 ` Darrick J. Wong [this message]
2020-07-29 4:37 ` Allison Collins
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=20200729012348.GD3151642@magnolia \
--to=darrick.wong@oracle.com \
--cc=allison.henderson@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/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 NNTP newsgroup(s).