mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Matthew Wilcox <willy@infradead.org>
Cc: Ethan Carter Edwards <ethan@ethancedwards.com>,
	Theodore Ts'o <tytso@mit.edu>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] ext4: hash: change kzalloc(n * sizeof, ...) to kcalloc(n, sizeof, ...)
Date: Sat, 15 Mar 2025 23:27:02 -0600	[thread overview]
Message-ID: <55E18A5B-49D0-4E8D-A252-DC7EF0BA691D@dilger.ca> (raw)
In-Reply-To: <Z9ZFabmQuSLiwfE5@casper.infradead.org>

[-- Attachment #1: Type: text/plain, Size: 866 bytes --]

On Mar 15, 2025, at 9:28 PM, Matthew Wilcox <willy@infradead.org> wrote:
> 
> On Sat, Mar 15, 2025 at 12:29:34PM -0400, Ethan Carter Edwards wrote:
>> Open coded arithmetic in allocator arguments is discouraged. Helper
>> functions like kcalloc are preferred.
> 
> Well, yes, but ...
> 
>> +++ b/fs/ext4/hash.c
>> @@ -302,7 +302,7 @@ int ext4fs_dirhash(const struct inode *dir, const char *name, int len,
>> 
>> 	if (len && IS_CASEFOLDED(dir) &&
>> 	   (!IS_ENCRYPTED(dir) || fscrypt_has_encryption_key(dir))) {
>> -		buff = kzalloc(sizeof(char) * PATH_MAX, GFP_KERNEL);
>> +		buff = kcalloc(PATH_MAX, sizeof(char), GFP_KERNEL);
> 
> sizeof(char) is defined to be 1.  So this should just be
> kzalloc(PATH_MAX, GFP_KERNEL).

I was going to say exactly the same thing.
Passing "1" to kcalloc() is just pure overhead.

Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

      reply	other threads:[~2025-03-16  5:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-15 16:29 Ethan Carter Edwards
2025-03-16  3:28 ` Matthew Wilcox
2025-03-16  5:27   ` Andreas Dilger [this message]

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=55E18A5B-49D0-4E8D-A252-DC7EF0BA691D@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=ethan@ethancedwards.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=willy@infradead.org \
    /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

all inboxes | Powered by JetHome®