public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] xfs: Use kvcalloc() instead of kvzalloc()
Date: Mon, 11 Oct 2021 15:58:38 -0700	[thread overview]
Message-ID: <20211011225838.GJ24307@magnolia> (raw)
In-Reply-To: <20210928223307.GA295934@embeddedor>

On Tue, Sep 28, 2021 at 05:33:07PM -0500, Gustavo A. R. Silva wrote:
> Use 2-factor argument multiplication form kvcalloc() instead of
> kvzalloc().
> 
> Link: https://github.com/KSPP/linux/issues/162
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Oooh, fun, checks for multiplication overflows.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_ioctl.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 0c795dc093ef..174cd8950cb6 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -1547,7 +1547,7 @@ xfs_ioc_getbmap(
>  	if (bmx.bmv_count > ULONG_MAX / recsize)
>  		return -ENOMEM;
>  
> -	buf = kvzalloc(bmx.bmv_count * sizeof(*buf), GFP_KERNEL);
> +	buf = kvcalloc(bmx.bmv_count, sizeof(*buf), GFP_KERNEL);
>  	if (!buf)
>  		return -ENOMEM;
>  
> @@ -1601,11 +1601,11 @@ xfs_ioc_getfsmap(
>  	 */
>  	count = min_t(unsigned int, head.fmh_count,
>  			131072 / sizeof(struct fsmap));
> -	recs = kvzalloc(count * sizeof(struct fsmap), GFP_KERNEL);
> +	recs = kvcalloc(count, sizeof(struct fsmap), GFP_KERNEL);
>  	if (!recs) {
>  		count = min_t(unsigned int, head.fmh_count,
>  				PAGE_SIZE / sizeof(struct fsmap));
> -		recs = kvzalloc(count * sizeof(struct fsmap), GFP_KERNEL);
> +		recs = kvcalloc(count, sizeof(struct fsmap), GFP_KERNEL);
>  		if (!recs)
>  			return -ENOMEM;
>  	}
> -- 
> 2.27.0
> 

      reply	other threads:[~2021-10-11 22:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 22:33 [PATCH][next] xfs: Use kvcalloc() instead of kvzalloc() Gustavo A. R. Silva
2021-10-11 22:58 ` Darrick J. Wong [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=20211011225838.GJ24307@magnolia \
    --to=djwong@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.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