Skip to contentSkip to conversation

xfs: use kmalloc_array() instead of kmalloc() in xfs_da_grow_inode_int

PATCH Superseded Cihan Karadag 2 participants 2 messages Jul 14 XFS filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: use kmalloc_array() instead of kmalloc() in xfs_da_grow_inode_int

Replace the open-coded

sizeof(*mapp) * count

multiplication with kmalloc_array(), based on kernel coding guidelines against open-coded arithmetic in allocator arguments.

---
 fs/xfs/libxfs/xfs_da_btree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_da_btree.c +1 -1
index 9debb95d86fa0..99e4318ba75f2 100644
@@ -2354,7 +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,
+		mapp = kmalloc_array(count, sizeof(*mapp),
 				GFP_KERNEL | __GFP_NOFAIL);
 		for (b = *bno, mapi = 0; b < *bno + count; ) {
 			c = (int)(*bno + count - b);
Signature · 1 line
2.54.0
#1 lore raw
Quoted 17 lines · Cihan Karadag

Replace the open-coded

sizeof(*mapp) * count

multiplication with kmalloc_array(), based on kernel coding guidelines against open-coded arithmetic in allocator arguments.

---
 fs/xfs/libxfs/xfs_da_btree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_da_btree.c +0 -0
index 9debb95d86fa0..99e4318ba75f2 100644

fs/xfs/libxfs/xfs_da_btree.c xfs_da_grow_inode_int( · line 2358

Quoted 6 lines
fs/xfs/libxfs/xfs_da_btree.c +1 -1
@@ -2354,7 +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,
+		mapp = kmalloc_array(count, sizeof(*mapp),
 				GFP_KERNEL | __GFP_NOFAIL);

kmalloc_objs?

--D

Quoted 6 lines
fs/xfs/libxfs/xfs_da_btree.c +0 -0
 		for (b = *bno, mapi = 0; b < *bno + count; ) {
 			c = (int)(*bno + count - b);
Signature · 1 line
2.54.0