public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu@kernel.org>
To: Rahul Kumar <rk0006818@gmail.com>
Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, linux-hyperv@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org
Subject: Re: [PATCH] drivers/hv: Use kmalloc_array() instead of kmalloc()
Date: Fri, 7 Nov 2025 06:52:29 +0000	[thread overview]
Message-ID: <20251107065229.GA3932045@liuwe-devbox-debian-v2.local> (raw)
In-Reply-To: <20251104121618.1396291-1-rk0006818@gmail.com>

On Tue, Nov 04, 2025 at 05:46:18PM +0530, Rahul Kumar wrote:
> Documentation/process/deprecated.rst recommends against the use of
> kmalloc with dynamic size calculations due to the risk of overflow and
> smaller allocation being made than the caller was expecting.
> 
> Replace kmalloc() with kmalloc_array() in hv_common.c to make the
> intended allocation size clearer and avoid potential overflow issues.
> 
> The number of pages (pgcount) is bounded, so overflow is not a
> practical concern here. However, using kmalloc_array() better reflects
> the intent to allocate an array and improves consistency with other
> allocations.
> 
> No functional change intended.
> 
> Signed-off-by: Rahul Kumar <rk0006818@gmail.com>

Applied to hyperv-next. Thanks.

> ---
>  drivers/hv/hv_common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index e109a620c83f..68689beb383c 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -487,7 +487,7 @@ int hv_common_cpu_init(unsigned int cpu)
>  	 * online and then taken offline
>  	 */
>  	if (!*inputarg) {
> -		mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags);
> +		mem = kmalloc_array(pgcount, HV_HYP_PAGE_SIZE, flags);
>  		if (!mem)
>  			return -ENOMEM;
>  
> -- 
> 2.43.0
> 

      reply	other threads:[~2025-11-07  6:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-04 12:16 [PATCH] drivers/hv: Use kmalloc_array() instead of kmalloc() Rahul Kumar
2025-11-07  6:52 ` Wei Liu [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=20251107065229.GA3932045@liuwe-devbox-debian-v2.local \
    --to=wei.liu@kernel.org \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rk0006818@gmail.com \
    --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