xfs: convert dquot iterator map allocation to kmalloc_array()
PATCH 1/1 xfs: convert dquot iterator map allocation to kmalloc_array()
Convert the open-coded kmalloc(n * sizeof(*p), ...) pattern in xfs_qm_dqiterate() to kmalloc_array(n, sizeof(*p), ...). This matches the convention adopted across fs/xfs/ in commit 910bbdf2f4dXX ("xfs:
convert buf_cancel_table allocation to kmalloc_array") and is the only remaining instance of the old pattern in fs/xfs/.
No functional change. XFS_DQITER_MAP_SIZE is a compile-time constant
(10) so the runtime overflow check added by kmalloc_array() folds away; the conversion is for consistency and to keep fs/xfs/ free of the deprecated form.
--- fs/xfs/xfs_qm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_qm.c +1 -1
@@ -1170,7 +1170,7 @@ xfs_qm_reset_dqcounts_buf(if (qip->i_nblocks ==0 )return 0 ; - map =kmalloc (XFS_DQITER_MAP_SIZE *sizeof (*map), + map =kmalloc_array (XFS_DQITER_MAP_SIZE ,sizeof (*map),GFP_KERNEL | __GFP_NOFAIL); lblkno =0 ;
Signature · 1 line
2.54.0
Quoted 6 lines · William Theesfeld
Convert the open-coded
kmalloc(n * sizeof(*p), ...)pattern inxfs_qm_dqiterate()tokmalloc_array(n, sizeof(*p), ...). This matches the convention adopted acrossfs/xfs/in commit 910bbdf2f4dXX ("xfs:
convertbuf_cancel_tableallocation tokmalloc_array") and is the only remaining instance of the old pattern infs/xfs/.
Quoted 6 lines
No functional change.
XFS_DQITER_MAP_SIZEis a compile-time constant
(10) so the runtime overflow check added bykmalloc_array()folds away; the conversion is for consistency and to keepfs/xfs/free of the deprecated form.Signed-off-by William Theesfeld <[email protected]>
Macros these days...
--D
Quoted 21 lines
--- fs/xfs/xfs_qm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/xfs/xfs_qm.c +1
-1@@ -1170,7 +1170,7 @@ xfs_qm_reset_dqcounts_buf(if (qip->i_nblocks ==0 )return 0 ; - map =kmalloc (XFS_DQITER_MAP_SIZE *sizeof (*map), + map =kmalloc_array (XFS_DQITER_MAP_SIZE ,sizeof (*map),GFP_KERNEL | __GFP_NOFAIL); lblkno =0 ;Signature · 1 line
2.54.0
Quoted 1 line · Darrick J. Wong
Macros these days...
In in the new world order this should be kmalloc_objs anyway.
And when we touch this, we should probably drop the NOFAIL and add allocation failure handling.
PATCH v2 1/1 xfs: convert dquot iterator map allocation to kmalloc_objs()
In reply to William Theesfeldv1 converted the open-coded kmalloc(N * sizeof(*p), ...) in xfs_qm_reset_dqcounts_buf() to kmalloc_array(). Per review feedback from Carlos Maiolino on the v1 thread, switch instead to the kmalloc_objs() helper, which is the preferred form for new XFS code and matches the style of recent conversions elsewhere in fs/xfs/.
While touching this, also drop the __GFP_NOFAIL flag and handle the allocation failure explicitly by returning -ENOMEM. The function already has callers that propagate errors out of quotacheck setup, so an early -ENOMEM is harmless and avoids relying on the allocator to retry forever on memory pressure.
No functional change for the success path.
--- fs/xfs/xfs_qm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/xfs/xfs_qm.c +3 -2
@@ -1170,8 +1170,9 @@ xfs_qm_reset_dqcounts_buf(if (qip->i_nblocks ==0 )return 0 ; - map =kmalloc (XFS_DQITER_MAP_SIZE *sizeof (*map), -GFP_KERNEL | __GFP_NOFAIL); + map =kmalloc_objs (*map,XFS_DQITER_MAP_SIZE ,GFP_KERNEL ); +if (!map) +return -ENOMEM ; lblkno =0 ; maxlblkcnt =XFS_B_TO_FSB (mp, mp->m_super->s_maxbytes);
Signature · 1 line
2.54.0
Carlos Maiolino
maintainerRe: [PATCH v2] xfs: convert dquot iterator map allocation to kmalloc_objs()
Quoted 3 lines · William Theesfeld
v1 converted the open-coded
kmalloc(N * sizeof(*p), ...)inxfs_qm_reset_dqcounts_buf()tokmalloc_array(). Per review feedback from Carlos Maiolino on the v1 thread, switch instead to the
Me? Wasn't Christoph?
Quoted 35 lines
kmalloc_objs()helper, which is the preferred form for new XFS code and matches the style of recent conversions elsewhere infs/xfs/.While touching this, also drop the
__GFP_NOFAILflag and handle the allocation failure explicitly by returning-ENOMEM. The function already has callers that propagate errors out of quotacheck setup, so an early-ENOMEMis harmless and avoids relying on the allocator to retry forever on memory pressure.No functional change for the success path.
Signed-off-by William Theesfeld <[email protected]>--- fs/xfs/xfs_qm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/xfs/xfs_qm.c +3
-2@@ -1170,8 +1170,9 @@ xfs_qm_reset_dqcounts_buf(if (qip->i_nblocks ==0 )return 0 ; - map =kmalloc (XFS_DQITER_MAP_SIZE *sizeof (*map), -GFP_KERNEL | __GFP_NOFAIL); + map =kmalloc_objs (*map,XFS_DQITER_MAP_SIZE ,GFP_KERNEL ); +if (!map) +return -ENOMEM ; lblkno =0 ; maxlblkcnt =XFS_B_TO_FSB (mp, mp->m_super->s_maxbytes);Signature · 1 line
2.54.0