public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>
To: Kriish Sharma <kriish.sharma2006@gmail.com>,
	Carlos Maiolino <cem@kernel.org>
Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-kernel-mentees@lists.linuxfoundation.org,
	skhan@linuxfoundation.org,  david.hunter.linux@gmail.com
Subject: Re: [PATCH] xfs: use kmalloc_array() instead of kmalloc() for map allocation
Date: Fri, 24 Oct 2025 12:19:46 +0530	[thread overview]
Message-ID: <47bc0211bd8cc5474fbb3edb5446e0e306ccb026.camel@gmail.com> (raw)
In-Reply-To: <20251018194528.1871298-1-kriish.sharma2006@gmail.com>

On Sat, 2025-10-18 at 19:45 +0000, Kriish Sharma wrote:
> Using kmalloc_array() better reflects the intent to allocate an array of
> map entries, and improves consistency with similar allocations across the
> kernel.
> 
> No functional change intended.
> 
> Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>
> ---
>  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 23ba84ec919a..34ec61e455ff 100644
> --- a/fs/xfs/xfs_qm.c
> +++ b/fs/xfs/xfs_qm.c
> @@ -1218,7 +1218,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);
I think kmalloc_array is more useful when the size of memory to be allocated is dynamic with
kmalloc_array doing some additional checks on the size that is being passed. In this case, both
XFS_QUITER_MAP_SIZE  and sizeof(*map) are constant i.e, we are allocating constant size memory, so
maybe this isn't quite necessary?

Definition of kmalloc_array()

static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
	if (size != 0 && n > SIZE_MAX / size)
		return NULL;
	return kmalloc(n * size, flags);
}


--NR
>  
>  	lblkno = 0;


      parent reply	other threads:[~2025-10-24  6:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <eeslnTm4EeKA2atDj3UKUcXAaGwgiPzioO9tR3Kf0pBEyUjxEO_9DaFIpNYIlc_9ey63h8gqdBsIt9Xjgn7AkA==@protonmail.internalid>
2025-10-18 19:45 ` [PATCH] xfs: use kmalloc_array() instead of kmalloc() for map allocation Kriish Sharma
2025-10-21  7:02   ` Carlos Maiolino
2025-10-21 14:51   ` Darrick J. Wong
2025-10-24  6:49   ` Nirjhar Roy (IBM) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47bc0211bd8cc5474fbb3edb5446e0e306ccb026.camel@gmail.com \
    --to=nirjhar.roy.lists@gmail.com \
    --cc=cem@kernel.org \
    --cc=david.hunter.linux@gmail.com \
    --cc=kriish.sharma2006@gmail.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox