public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: "Miquel Sabaté Solà" <mssola@mssola.com>
Cc: dsterba@suse.com, clm@fb.com, naohiro.aota@wdc.com,
	kees@kernel.org, linux-btrfs@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] btrfs: replace kcalloc() calls to kzalloc_objs()
Date: Fri, 27 Feb 2026 01:27:27 +0100	[thread overview]
Message-ID: <20260227002727.GJ26902@twin.jikos.cz> (raw)
In-Reply-To: <20260224214544.562283-1-mssola@mssola.com>

On Tue, Feb 24, 2026 at 10:45:44PM +0100, Miquel Sabaté Solà wrote:
> Commit 2932ba8d9c99 ("slab: Introduce kmalloc_obj() and family")
> introduced, among many others, the kzalloc_objs() helper, which has some
> benefits over kcalloc(). Namely, internal introspection of the allocated
> type now becomes possible, allowing for future alignment-aware choices
> to be made by the allocator and future hardening work that can be type
> sensitive. Dropping 'sizeof' comes also as a nice side-effect.
> 
> Moreover, this also allows us to be in line with the recent tree-wide
> migration to the kmalloc_obj() and family of helpers. See
> commit 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for
> non-scalar types").
> 
> Reviewed-by: Kees Cook <kees@kernel.org>
> Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>

Added to for-next, thanks.

> -	buf = kcalloc(map->num_stripes, sizeof(u64), GFP_NOFS);
> +	buf = kzalloc_objs(*buf, map->num_stripes, GFP_NOFS);

> -	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);

> -	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);

I've changed it to the type in the above cases so it's a direct
conversion that only removes the sizeof(). For the rest there are no
strong preferences so we'll keep it as is, and my preference for new code
is to use the types.

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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24 21:45 [PATCH v2] btrfs: replace kcalloc() calls to kzalloc_objs() Miquel Sabaté Solà
2026-02-27  0:27 ` David Sterba [this message]
2026-02-27  6:47   ` 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=20260227002727.GJ26902@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=kees@kernel.org \
    --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