[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <222e0a61-d046-89fc-d46b-ac8da3ca7828@opensource.wdc.com>
Date: Mon, 28 Mar 2022 13:07:58 +0900
From: Damien Le Moal <damien.lemoal@...nsource.wdc.com>
To: cgel.zte@...il.com, djwong@...nel.org
Cc: linux-xfs@...r.kernel.org, dchinner@...hat.com,
chandan.babu@...cle.com, bfoster@...hat.com,
allison.henderson@...cle.com, lv.ruyi@....com.cn,
linux-kernel@...r.kernel.org, Zeal Robot <zealci@....com.cn>
Subject: Re: [PATCH] fs: xfs: add NULL pointer check
On 3/28/22 12:40, Damien Le Moal wrote:
> On 3/28/22 12:26, cgel.zte@...il.com wrote:
>> From: Lv Ruyi <lv.ruyi@....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@....com.cn>
>> Signed-off-by: Lv Ruyi <lv.ruyi@....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.
Note: this comment is not 100% correct. kmem_alloc() can fail if
KM_MAYFAIL is specified as a flag. But that is not the case here.
>
>> + 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
Powered by blists - more mailing lists