fs/ext4/hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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>
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).
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
© 2016 - 2025 Red Hat, Inc.