lkml.org 
[lkml]   [2022]   [Mar]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] fs: xfs: add NULL pointer check
Date
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);
+ 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
--
2.25.1
\
 
 \ /
  Last update: 2022-03-28 05:27    [W:0.067 / U:0.624 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site