Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: simplify xfs_idata_realloc

Streamline the code and take advantage of the fact that kmem_realloc
through krealloc will be have like a normal allocation if passing in a
NULL old pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

authored by

Christoph Hellwig and committed by
Darrick J. Wong
1216b58b fcacbc3f

+19 -36
+19 -36
fs/xfs/libxfs/xfs_inode_fork.c
··· 468 468 */ 469 469 void 470 470 xfs_idata_realloc( 471 - xfs_inode_t *ip, 472 - int byte_diff, 473 - int whichfork) 471 + struct xfs_inode *ip, 472 + int byte_diff, 473 + int whichfork) 474 474 { 475 - xfs_ifork_t *ifp; 476 - int new_size; 477 - int real_size; 475 + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); 476 + int new_size = (int)ifp->if_bytes + byte_diff; 478 477 479 - if (byte_diff == 0) { 480 - return; 481 - } 482 - 483 - ifp = XFS_IFORK_PTR(ip, whichfork); 484 - new_size = (int)ifp->if_bytes + byte_diff; 485 478 ASSERT(new_size >= 0); 479 + ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork)); 480 + 481 + if (byte_diff == 0) 482 + return; 486 483 487 484 if (new_size == 0) { 488 485 kmem_free(ifp->if_u1.if_data); 489 486 ifp->if_u1.if_data = NULL; 490 - real_size = 0; 491 - } else { 492 - /* 493 - * Stuck with malloc/realloc. 494 - * For inline data, the underlying buffer must be 495 - * a multiple of 4 bytes in size so that it can be 496 - * logged and stay on word boundaries. We enforce 497 - * that here. 498 - */ 499 - real_size = roundup(new_size, 4); 500 - if (ifp->if_u1.if_data == NULL) { 501 - ifp->if_u1.if_data = kmem_alloc(real_size, 502 - KM_SLEEP | KM_NOFS); 503 - } else { 504 - /* 505 - * Only do the realloc if the underlying size 506 - * is really changing. 507 - */ 508 - ifp->if_u1.if_data = 509 - kmem_realloc(ifp->if_u1.if_data, 510 - real_size, 511 - KM_SLEEP | KM_NOFS); 512 - } 487 + ifp->if_bytes = 0; 488 + return; 513 489 } 490 + 491 + /* 492 + * For inline data, the underlying buffer must be a multiple of 4 bytes 493 + * in size so that it can be logged and stay on word boundaries. 494 + * We enforce that here. 495 + */ 496 + ifp->if_u1.if_data = kmem_realloc(ifp->if_u1.if_data, 497 + roundup(new_size, 4), KM_SLEEP | KM_NOFS); 514 498 ifp->if_bytes = new_size; 515 - ASSERT(ifp->if_bytes <= XFS_IFORK_SIZE(ip, whichfork)); 516 499 } 517 500 518 501 void