Re: [PATCH] btrfs: replace kcalloc() calls to kzalloc_objs()

From: Miquel Sabaté Solà

Date: Tue Feb 24 2026 - 07:25:50 EST


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: signature.asc
Description: PGP signature