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

From: Miquel Sabaté Solà

Date: Tue Feb 24 2026 - 01:23:50 EST


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.

>
> Reviewed-by: Kees Cook <kees@xxxxxxxxxx>

Thanks!
Miquel

Attachment: signature.asc
Description: PGP signature