[PATCH v2] xfs: use kmalloc_objs() instead of kmalloc() in xfs_da_grow_inode_int

Cihan Karadag posted 1 patch 1 week, 1 day ago
fs/xfs/libxfs/xfs_da_btree.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH v2] xfs: use kmalloc_objs() instead of kmalloc() in xfs_da_grow_inode_int
Posted by Cihan Karadag 1 week, 1 day ago
Convert open-coded kmalloc() multiplication to the modern kmalloc_objs()
interface to improve type safety and prevent potential integer
overflows.

No functional changes are intended.

Signed-off-by: Cihan Karadag <cihan.cihan@gmail.com>
---
Changes since v1:
- Use kmalloc_objs() instead of kmalloc_array(), per Darrick's suggestion.

 fs/xfs/libxfs/xfs_da_btree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
index 9debb95d86fa0..f190c088591bc 100644
--- a/fs/xfs/libxfs/xfs_da_btree.c
+++ b/fs/xfs/libxfs/xfs_da_btree.c
@@ -2354,8 +2354,7 @@ xfs_da_grow_inode_int(
 		 * If we didn't get it and the block might work if fragmented,
 		 * try without the CONTIG flag.  Loop until we get it all.
 		 */
-		mapp = kmalloc(sizeof(*mapp) * count,
-				GFP_KERNEL | __GFP_NOFAIL);
+		mapp = kmalloc_objs(*mapp, count, GFP_KERNEL | __GFP_NOFAIL);
 		for (b = *bno, mapi = 0; b < *bno + count; ) {
 			c = (int)(*bno + count - b);
 			nmap = min(XFS_BMAP_MAX_NMAP, c);
-- 
2.54.0
Re: [PATCH v2] xfs: use kmalloc_objs() instead of kmalloc() in xfs_da_grow_inode_int
Posted by Carlos Maiolino 3 days, 18 hours ago
On Thu, 16 Jul 2026 15:48:12 -0600, Cihan Karadag wrote:
> Convert open-coded kmalloc() multiplication to the modern kmalloc_objs()
> interface to improve type safety and prevent potential integer
> overflows.
> 
> No functional changes are intended.
> 
> 
> [...]

Applied to for-next, thanks!

[1/1] xfs: use kmalloc_objs() instead of kmalloc() in xfs_da_grow_inode_int
      commit: 97f34168769238b1fe4412229c99f1a78364f6f9

Best regards,
-- 
Carlos Maiolino <cem@kernel.org>
Re: [PATCH v2] xfs: use kmalloc_objs() instead of kmalloc() in xfs_da_grow_inode_int
Posted by Carlos Maiolino 4 days, 20 hours ago
On Thu, Jul 16, 2026 at 03:48:12PM -0600, Cihan Karadag wrote:
> Convert open-coded kmalloc() multiplication to the modern kmalloc_objs()
> interface to improve type safety and prevent potential integer
> overflows.
> 
> No functional changes are intended.
> 
> Signed-off-by: Cihan Karadag <cihan.cihan@gmail.com>

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

> ---
> Changes since v1:
> - Use kmalloc_objs() instead of kmalloc_array(), per Darrick's suggestion.
> 
>  fs/xfs/libxfs/xfs_da_btree.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
> index 9debb95d86fa0..f190c088591bc 100644
> --- a/fs/xfs/libxfs/xfs_da_btree.c
> +++ b/fs/xfs/libxfs/xfs_da_btree.c
> @@ -2354,8 +2354,7 @@ xfs_da_grow_inode_int(
>  		 * If we didn't get it and the block might work if fragmented,
>  		 * try without the CONTIG flag.  Loop until we get it all.
>  		 */
> -		mapp = kmalloc(sizeof(*mapp) * count,
> -				GFP_KERNEL | __GFP_NOFAIL);
> +		mapp = kmalloc_objs(*mapp, count, GFP_KERNEL | __GFP_NOFAIL);
>  		for (b = *bno, mapi = 0; b < *bno + count; ) {
>  			c = (int)(*bno + count - b);
>  			nmap = min(XFS_BMAP_MAX_NMAP, c);
> -- 
> 2.54.0
>
Re: [PATCH v2] xfs: use kmalloc_objs() instead of kmalloc() in xfs_da_grow_inode_int
Posted by Darrick J. Wong 1 week ago
On Thu, Jul 16, 2026 at 03:48:12PM -0600, Cihan Karadag wrote:
> Convert open-coded kmalloc() multiplication to the modern kmalloc_objs()
> interface to improve type safety and prevent potential integer
> overflows.
> 
> No functional changes are intended.
> 
> Signed-off-by: Cihan Karadag <cihan.cihan@gmail.com>

Looks ok,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
> Changes since v1:
> - Use kmalloc_objs() instead of kmalloc_array(), per Darrick's suggestion.
> 
>  fs/xfs/libxfs/xfs_da_btree.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
> index 9debb95d86fa0..f190c088591bc 100644
> --- a/fs/xfs/libxfs/xfs_da_btree.c
> +++ b/fs/xfs/libxfs/xfs_da_btree.c
> @@ -2354,8 +2354,7 @@ xfs_da_grow_inode_int(
>  		 * If we didn't get it and the block might work if fragmented,
>  		 * try without the CONTIG flag.  Loop until we get it all.
>  		 */
> -		mapp = kmalloc(sizeof(*mapp) * count,
> -				GFP_KERNEL | __GFP_NOFAIL);
> +		mapp = kmalloc_objs(*mapp, count, GFP_KERNEL | __GFP_NOFAIL);
>  		for (b = *bno, mapi = 0; b < *bno + count; ) {
>  			c = (int)(*bno + count - b);
>  			nmap = min(XFS_BMAP_MAX_NMAP, c);
> -- 
> 2.54.0
> 
>