* [PATCH] ext4: hash: change kzalloc(n * sizeof, ...) to kcalloc(n, sizeof, ...)
@ 2025-03-15 16:29 Ethan Carter Edwards
2025-03-16 3:28 ` Matthew Wilcox
0 siblings, 1 reply; 3+ messages in thread
From: Ethan Carter Edwards @ 2025-03-15 16:29 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger
Cc: linux-ext4, linux-kernel, linux-fsdevel, linux-hardening,
Ethan Carter Edwards
Open coded arithmetic in allocator arguments is discouraged. Helper
functions like kcalloc are preferred.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
fs/ext4/hash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
index deabe29da7fbc3d35f674ff861a2f3b579ffdea2..7a9afac1597c69f319f02bb816ca797d32c188ca 100644
--- a/fs/ext4/hash.c
+++ 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);
if (!buff)
return -ENOMEM;
---
base-commit: da920b7df701770e006928053672147075587fb2
change-id: 20250315-ext4-hash-kcalloc-203033977bd9
Best regards,
--
Ethan Carter Edwards <ethan@ethancedwards.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: hash: change kzalloc(n * sizeof, ...) to kcalloc(n, sizeof, ...)
2025-03-15 16:29 [PATCH] ext4: hash: change kzalloc(n * sizeof, ...) to kcalloc(n, sizeof, ...) Ethan Carter Edwards
@ 2025-03-16 3:28 ` Matthew Wilcox
2025-03-16 5:27 ` Andreas Dilger
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2025-03-16 3:28 UTC (permalink / raw)
To: Ethan Carter Edwards
Cc: Theodore Ts'o, Andreas Dilger, linux-ext4, linux-kernel,
linux-fsdevel, linux-hardening
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).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: hash: change kzalloc(n * sizeof, ...) to kcalloc(n, sizeof, ...)
2025-03-16 3:28 ` Matthew Wilcox
@ 2025-03-16 5:27 ` Andreas Dilger
0 siblings, 0 replies; 3+ messages in thread
From: Andreas Dilger @ 2025-03-16 5:27 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Ethan Carter Edwards, Theodore Ts'o, Ext4 Developers List,
LKML, linux-fsdevel, linux-hardening
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-16 5:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-15 16:29 [PATCH] ext4: hash: change kzalloc(n * sizeof, ...) to kcalloc(n, sizeof, ...) Ethan Carter Edwards
2025-03-16 3:28 ` Matthew Wilcox
2025-03-16 5:27 ` Andreas Dilger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox