diff mbox series

[2/2] xfs: remove the extra processing of zero size in xfs_idata_realloc()

Message ID 20201124104531.561-3-thunder.leizhen@huawei.com (mailing list archive)
State New
Headers show
Series xfs: check krealloc() return value and simplify code | expand

Commit Message

Zhen Lei Nov. 24, 2020, 10:45 a.m. UTC
krealloc() does the free operation when the parameter new_size is 0, with
ZERO_SIZE_PTR returned. Because all other places use NULL to check whether
if_data is available or not, so covert it from ZERO_SIZE_PTR to NULL.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 fs/xfs/libxfs/xfs_inode_fork.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

Comments

Christoph Hellwig Nov. 24, 2020, 11:52 a.m. UTC | #1
On Tue, Nov 24, 2020 at 06:45:31PM +0800, Zhen Lei wrote:
> krealloc() does the free operation when the parameter new_size is 0, with
> ZERO_SIZE_PTR returned. Because all other places use NULL to check whether
> if_data is available or not, so covert it from ZERO_SIZE_PTR to NULL.

This new code looks much harder to read than the version it replaced.
Zhen Lei Nov. 24, 2020, 12:05 p.m. UTC | #2
On 2020/11/24 19:52, Christoph Hellwig wrote:
> On Tue, Nov 24, 2020 at 06:45:31PM +0800, Zhen Lei wrote:
>> krealloc() does the free operation when the parameter new_size is 0, with
>> ZERO_SIZE_PTR returned. Because all other places use NULL to check whether
>> if_data is available or not, so covert it from ZERO_SIZE_PTR to NULL.
> 
> This new code looks much harder to read than the version it replaced.

OK

> 
>
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
index 4e457aea8493..518af4088e79 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.c
+++ b/fs/xfs/libxfs/xfs_inode_fork.c
@@ -492,13 +492,6 @@  xfs_idata_realloc(
 	if (byte_diff == 0)
 		return;
 
-	if (new_size == 0) {
-		kmem_free(ifp->if_u1.if_data);
-		ifp->if_u1.if_data = NULL;
-		ifp->if_bytes = 0;
-		return;
-	}
-
 	/*
 	 * For inline data, the underlying buffer must be a multiple of 4 bytes
 	 * in size so that it can be logged and stay on word boundaries.
@@ -510,7 +503,7 @@  xfs_idata_realloc(
 		WARN(1, "if_data realloc failed\n");
 		return;
 	}
-	ifp->if_u1.if_data = if_data;
+	ifp->if_u1.if_data = ZERO_OR_NULL_PTR(if_data) ? NULL : if_data;
 	ifp->if_bytes = new_size;
 }