From: "Miquel Sabaté Solà" <mssola@mssola.com>
To: David Sterba <dsterba@suse.cz>
Cc: Kees Cook <kees@kernel.org>,
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: Tue, 24 Feb 2026 13:23:22 +0100 [thread overview]
Message-ID: <871pias539.fsf@> (raw)
In-Reply-To: <20260224112905.GQ26902@suse.cz> (David Sterba's message of "Tue, 24 Feb 2026 12:29:05 +0100")
[-- Attachment #1: Type: text/plain, Size: 2242 bytes --]
David Sterba @ 2026-02-24 12:29 +01:
> On Tue, Feb 24, 2026 at 07:23:25AM +0100, Miquel Sabaté Solà wrote:
>> Kees Cook @ 2026-02-23 16:06 -08:
>>
>> > 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!
>>
>> I personally don't mind either way, but I don't what's the policy around
>> using "auto" in btrfs.
>
> So far it hasn't been used and as with all the other syntax updates it's
> up to debate and eventually start using it or not. I'd need to see
> examples where it's better than not using it, apart from macros.
> In C the explicit types are everywhere and are I think always simple,
> unlike in C++ where 'auto' can hide something very complex.
In this case, I'd say we can skip the use of 'auto', at least for these
patches. Using it wouldn't help much, and it's more coherent with the
rest of the codebase to stick with explicit typing.
Also, using 'auto' in this case would mean to remove the declaration
from the top of the function, which would break the style for this and
many other functions from the btrfs code.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 897 bytes --]
next prev parent reply other threads:[~2026-02-24 12:23 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
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à [this message]
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=871pias539.fsf@ \
--to=mssola@mssola.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--cc=kees@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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