mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: cgel.zte@gmail.com, djwong@kernel.org
Cc: linux-xfs@vger.kernel.org, dchinner@redhat.com,
	chandan.babu@oracle.com, bfoster@redhat.com,
	allison.henderson@oracle.com, lv.ruyi@zte.com.cn,
	linux-kernel@vger.kernel.org, Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] fs: xfs: add NULL pointer check
Date: Mon, 28 Mar 2022 12:40:59 +0900	[thread overview]
Message-ID: <32fad707-fdab-75a6-f7e5-d356a0b86983@opensource.wdc.com> (raw)
In-Reply-To: <20220328032642.2371596-1-lv.ruyi@zte.com.cn>

On 3/28/22 12:26, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
> 
> kmem_zalloc() is a memory allocation function which can return NULL when
> some internal memory errors happen. It is safer to check NULL pointer.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
> ---
>  fs/xfs/libxfs/xfs_attr_leaf.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
> index 014daa8c542d..e6694f49f563 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -1571,6 +1571,8 @@ xfs_attr3_leaf_compact(
>  	trace_xfs_attr_leaf_compact(args);
>  
>  	tmpbuffer = kmem_alloc(args->geo->blksize, 0);

See kmem_alloc() code: this function cannot fail (it retries the
allocation until success). So checking for NULL pointer does not make sense.

> +	if (!tmpbuffer)
> +		return;
>  	memcpy(tmpbuffer, bp->b_addr, args->geo->blksize);
>  	memset(bp->b_addr, 0, args->geo->blksize);
>  	leaf_src = (xfs_attr_leafblock_t *)tmpbuffer;
> @@ -2290,6 +2292,8 @@ xfs_attr3_leaf_unbalance(
>  		struct xfs_attr3_icleaf_hdr tmphdr;
>  
>  		tmp_leaf = kmem_zalloc(state->args->geo->blksize, 0);
> +		if (!tmp_leaf)
> +			return;
>  
>  		/*
>  		 * Copy the header into the temp leaf so that all the stuff


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2022-03-28  3:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28  3:26 cgel.zte
2022-03-28  3:40 ` Damien Le Moal [this message]
2022-03-28  3:55   ` Lv Ruyi
2022-03-28  4:07   ` Damien Le Moal

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=32fad707-fdab-75a6-f7e5-d356a0b86983@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=allison.henderson@oracle.com \
    --cc=bfoster@redhat.com \
    --cc=cgel.zte@gmail.com \
    --cc=chandan.babu@oracle.com \
    --cc=dchinner@redhat.com \
    --cc=djwong@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lv.ruyi@zte.com.cn \
    --cc=zealci@zte.com.cn \
    /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

all inboxes | Powered by JetHome®