* [PATCH] xfs: convert dquot iterator map allocation to kmalloc_array()
@ 2026-06-01 19:18 William Theesfeld
2026-06-02 5:14 ` Darrick J. Wong
2026-06-02 11:25 ` [PATCH v2] xfs: convert dquot iterator map allocation to kmalloc_objs() William Theesfeld
0 siblings, 2 replies; 5+ messages in thread
From: William Theesfeld @ 2026-06-01 19:18 UTC (permalink / raw)
To: Carlos Maiolino; +Cc: linux-xfs, linux-kernel
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.
Signed-off-by: William Theesfeld <william@theesfeld.net>
---
fs/xfs/xfs_qm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
index 7bd15d9e7..eebdeb181 100644
--- a/fs/xfs/xfs_qm.c
+++ b/fs/xfs/xfs_qm.c
@@ -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;
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: convert dquot iterator map allocation to kmalloc_array()
2026-06-01 19:18 [PATCH] xfs: convert dquot iterator map allocation to kmalloc_array() William Theesfeld
@ 2026-06-02 5:14 ` Darrick J. Wong
2026-06-02 5:56 ` Christoph Hellwig
2026-06-02 11:25 ` [PATCH v2] xfs: convert dquot iterator map allocation to kmalloc_objs() William Theesfeld
1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2026-06-02 5:14 UTC (permalink / raw)
To: William Theesfeld; +Cc: Carlos Maiolino, linux-xfs, linux-kernel
On Mon, Jun 01, 2026 at 03:18:57PM -0400, William Theesfeld wrote:
> 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.
>
> Signed-off-by: William Theesfeld <william@theesfeld.net>
Macros these days...
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> fs/xfs/xfs_qm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
> index 7bd15d9e7..eebdeb181 100644
> --- a/fs/xfs/xfs_qm.c
> +++ b/fs/xfs/xfs_qm.c
> @@ -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;
> --
> 2.54.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: convert dquot iterator map allocation to kmalloc_array()
2026-06-02 5:14 ` Darrick J. Wong
@ 2026-06-02 5:56 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2026-06-02 5:56 UTC (permalink / raw)
To: Darrick J. Wong
Cc: William Theesfeld, Carlos Maiolino, linux-xfs, linux-kernel
On Mon, Jun 01, 2026 at 10:14:44PM -0700, Darrick J. Wong wrote:
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] xfs: convert dquot iterator map allocation to kmalloc_objs()
2026-06-01 19:18 [PATCH] xfs: convert dquot iterator map allocation to kmalloc_array() William Theesfeld
2026-06-02 5:14 ` Darrick J. Wong
@ 2026-06-02 11:25 ` William Theesfeld
2026-06-02 14:01 ` Carlos Maiolino
1 sibling, 1 reply; 5+ messages in thread
From: William Theesfeld @ 2026-06-02 11:25 UTC (permalink / raw)
To: Carlos Maiolino; +Cc: Darrick J . Wong, linux-xfs, linux-kernel
v1 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.
Signed-off-by: William Theesfeld <william@theesfeld.net>
---
fs/xfs/xfs_qm.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
index 7bd15d9e7..83e8d80bc 100644
--- a/fs/xfs/xfs_qm.c
+++ b/fs/xfs/xfs_qm.c
@@ -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);
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] xfs: convert dquot iterator map allocation to kmalloc_objs()
2026-06-02 11:25 ` [PATCH v2] xfs: convert dquot iterator map allocation to kmalloc_objs() William Theesfeld
@ 2026-06-02 14:01 ` Carlos Maiolino
0 siblings, 0 replies; 5+ messages in thread
From: Carlos Maiolino @ 2026-06-02 14:01 UTC (permalink / raw)
To: William Theesfeld; +Cc: Darrick J . Wong, linux-xfs, linux-kernel
On Tue, Jun 02, 2026 at 07:25:08AM -0400, William Theesfeld wrote:
> v1 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
Me? Wasn't Christoph?
> 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.
>
> Signed-off-by: William Theesfeld <william@theesfeld.net>
> ---
> fs/xfs/xfs_qm.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
> index 7bd15d9e7..83e8d80bc 100644
> --- a/fs/xfs/xfs_qm.c
> +++ b/fs/xfs/xfs_qm.c
> @@ -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);
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-02 14:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-01 19:18 [PATCH] xfs: convert dquot iterator map allocation to kmalloc_array() William Theesfeld
2026-06-02 5:14 ` Darrick J. Wong
2026-06-02 5:56 ` Christoph Hellwig
2026-06-02 11:25 ` [PATCH v2] xfs: convert dquot iterator map allocation to kmalloc_objs() William Theesfeld
2026-06-02 14:01 ` Carlos Maiolino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®