Skip to contentSkip to conversation

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

PATCH Applied Cihan Karadag 3 participants 4 messages Jul 16 – Jul 21 XFS filesystem

lore
Share & tools
lore
#0 lore raw

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

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.

---
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(-)
fs/xfs/libxfs/xfs_da_btree.c +1 -2
index 9debb95d86fa0..f190c088591bc 100644
@@ -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);
Signature · 1 line
2.54.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Cihan Karadag

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.

Looks ok,

--D

Quoted 25 lines

---
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(-)
fs/xfs/libxfs/xfs_da_btree.c +1 -2
index 9debb95d86fa0..f190c088591bc 100644
@@ -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);
Signature · 1 line
2.54.0
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Cihan Karadag
Quoted 7 lines · Cihan Karadag

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.

Quoted 24 lines

---
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(-)
fs/xfs/libxfs/xfs_da_btree.c +1 -2
index 9debb95d86fa0..f190c088591bc 100644
@@ -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);
Signature · 1 line
2.54.0
maintainer Applied
#3 lore raw
In reply to Cihan Karadag
Quoted 8 lines · Cihan Karadag

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,

Signature · 1 line
Carlos Maiolino <[email protected]>