public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: "Miquel Sabaté Solà" <mssola@mssola.com>
Cc: dsterba@suse.com, clm@fb.com, naohiro.aota@wdc.com,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: replace kcalloc() calls to kzalloc_objs()
Date: Mon, 23 Feb 2026 16:06:12 -0800	[thread overview]
Message-ID: <202602231603.4F93301E@keescook> (raw)
In-Reply-To: <20260223234451.277369-1-mssola@mssola.com>

On Tue, Feb 24, 2026 at 12:44:51AM +0100, Miquel Sabaté Solà wrote:
> diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
> index 02105d68accb..1ebfed8f0a0a 100644
> --- a/fs/btrfs/raid56.c
> +++ b/fs/btrfs/raid56.c
> @@ -2110,8 +2110,8 @@ static int recover_sectors(struct btrfs_raid_bio *rbio)
>  	 * @unmap_array stores copy of pointers that does not get reordered
>  	 * during reconstruction so that kunmap_local works.
>  	 */
> -	pointers = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS);
> -	unmap_array = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS);
> +	pointers = kzalloc_objs(*pointers, rbio->real_stripes, GFP_NOFS);
> +	unmap_array = kzalloc_objs(*unmap_array, rbio->real_stripes, GFP_NOFS);
>  	if (!pointers || !unmap_array) {
>  		ret = -ENOMEM;
>  		goto out;

Just as a style option, I wanted to point out (for at least the above,
I didn't check the rest), you can do the definition and declaration at
once with "auto" and put the type in the alloc:

	auto pointers = kzalloc_objs(void *, rbio->real_stripes, GFP_NOFS);

But either way is fine. :) This patch looks good to me!

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

  reply	other threads:[~2026-02-24  0:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-23 23:44 [PATCH] btrfs: replace kcalloc() calls to kzalloc_objs() Miquel Sabaté Solà
2026-02-24  0:06 ` Kees Cook [this message]
2026-02-24  6:23   ` Miquel Sabaté Solà
     [not found]   ` <699d43e6.170a0220.3a6e96.a235SMTPIN_ADDED_BROKEN@mx.google.com>
2026-02-24 11:29     ` David Sterba
2026-02-24 12:23       ` Miquel Sabaté Solà
2026-02-24  4:37 ` Qu Wenruo
2026-02-24  4:42   ` Qu Wenruo
2026-02-24 13:52     ` David Sterba
2026-02-24  6:36   ` Miquel Sabaté Solà
     [not found]   ` <699d4704.050a0220.1a6450.86d7SMTPIN_ADDED_BROKEN@mx.google.com>
2026-02-24  6:48     ` Qu Wenruo
2026-02-24  8:59       ` Miquel Sabaté Solà
2026-02-24 14:55   ` David Laight
2026-02-25 14:44     ` David Sterba
2026-02-25 17:11       ` David Laight
2026-02-24  6:32 ` Johannes Thumshirn
2026-02-24  6:46   ` Miquel Sabaté Solà
2026-02-24  6:54     ` Qu Wenruo
2026-02-24  9:04       ` Miquel Sabaté Solà

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=202602231603.4F93301E@keescook \
    --to=kees@kernel.org \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mssola@mssola.com \
    --cc=naohiro.aota@wdc.com \
    /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