Skip to contentSkip to conversation

namespace: Replace simple_strtoul with kstrtoul to parse boot params

PATCH Applied Thorsten Blum 3 participants 5 messages Dec 14, 2025 – Dec 24, 2025 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 namespace: Replace simple_strtoul with kstrtoul to parse boot params

Replace simple_strtoul() with the recommended kstrtoul() for parsing the 'mhash_entries=' and 'mphash_entries=' boot parameters.

Check the return value of kstrtoul() and reject invalid values. This adds error handling while preserving behavior for existing values, and removes use of the deprecated simple_strtoul() helper.

---
 fs/namespace.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
fs/namespace.c +2 -8
index c58674a20cad..a548369ddb9c 100644
@@ -49,20 +49,14 @@ static unsigned int mp_hash_shift __ro_after_init;
 static __initdata unsigned long mhash_entries;
 static int __init set_mhash_entries(char *str)
 {
-	if (!str)
-		return 0;
-	mhash_entries = simple_strtoul(str, &str, 0);
-	return 1;
+	return kstrtoul(str, 0, &mhash_entries) == 0;
 }
 __setup("mhash_entries=", set_mhash_entries);
 
 static __initdata unsigned long mphash_entries;
 static int __init set_mphash_entries(char *str)
 {
-	if (!str)
-		return 0;
-	mphash_entries = simple_strtoul(str, &str, 0);
-	return 1;
+	return kstrtoul(str, 0, &mphash_entries) == 0;
 }
 __setup("mphash_entries=", set_mphash_entries);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
reviewer
#1 lore raw
Quoted 8 lines · Thorsten Blum

Replace simple_strtoul() with the recommended kstrtoul() for parsing the 'mhash_entries=' and 'mphash_entries=' boot parameters.

Check the return value of kstrtoul() and reject invalid values. This adds error handling while preserving behavior for existing values, and removes use of the deprecated simple_strtoul() helper.

...

fs/namespace.c static unsigned int mp_hash_shift __ro_after_init; · line 54

Quoted 11 lines
fs/namespace.c +1 -4
@@ -49,20 +49,14 @@ static unsigned int mp_hash_shift __ro_after_init;
 static __initdata unsigned long mhash_entries;
 static int __init set_mhash_entries(char *str)
 {
-	if (!str)
-		return 0;
-	mhash_entries = simple_strtoul(str, &str, 0);
-	return 1;
+	return kstrtoul(str, 0, &mhash_entries) == 0;
 }
 __setup("mhash_entries=", set_mhash_entries);

I'm not very experienced with the cmdline option parsing but AFAICT the 'str' argument can be indeed NULL and kstrtoul() will not be happy with that?

fs/namespace.c static unsigned int mp_hash_shift __ro_after_init; · line 61

Quoted 10 lines
fs/namespace.c +1 -4
 static __initdata unsigned long mphash_entries;
 static int __init set_mphash_entries(char *str)
 {
-	if (!str)
-		return 0;
-	mphash_entries = simple_strtoul(str, &str, 0);
-	return 1;
+	return kstrtoul(str, 0, &mphash_entries) == 0;
 }
 __setup("mphash_entries=", set_mphash_entries);

Similar here.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 12 lines · Jan Kara
Quoted 8 lines · Thorsten Blum

Replace simple_strtoul() with the recommended kstrtoul() for parsing the 'mhash_entries=' and 'mphash_entries=' boot parameters.

Check the return value of kstrtoul() and reject invalid values. This adds error handling while preserving behavior for existing values, and removes use of the deprecated simple_strtoul() helper.

...

Quoted 15 lines

fs/namespace.c static unsigned int mp_hash_shift __ro_after_init; · line 54

Quoted 11 lines
fs/namespace.c +1 -4
@@ -49,20 +49,14 @@ static unsigned int mp_hash_shift __ro_after_init;
 static __initdata unsigned long mhash_entries;
 static int __init set_mhash_entries(char *str)
 {
-	if (!str)
-		return 0;
-	mhash_entries = simple_strtoul(str, &str, 0);
-	return 1;
+	return kstrtoul(str, 0, &mhash_entries) == 0;
 }
 __setup("mhash_entries=", set_mhash_entries);

I'm not very experienced with the cmdline option parsing but AFAICT the 'str' argument can be indeed NULL and kstrtoul() will not be happy with that?

I don't think 'str' can be NULL. If you don't pass a value, 'str' will be the empty string (just tested this).

Thanks,
Thorsten

reviewer Reviewed-by
#3 lore raw
Quoted 29 lines · Thorsten Blum
Quoted 12 lines · Jan Kara
Quoted 8 lines · Thorsten Blum

Replace simple_strtoul() with the recommended kstrtoul() for parsing the 'mhash_entries=' and 'mphash_entries=' boot parameters.

Check the return value of kstrtoul() and reject invalid values. This adds error handling while preserving behavior for existing values, and removes use of the deprecated simple_strtoul() helper.

...

Quoted 15 lines

fs/namespace.c static unsigned int mp_hash_shift __ro_after_init; · line 54

Quoted 11 lines
fs/namespace.c +1 -4
@@ -49,20 +49,14 @@ static unsigned int mp_hash_shift __ro_after_init;
 static __initdata unsigned long mhash_entries;
 static int __init set_mhash_entries(char *str)
 {
-	if (!str)
-		return 0;
-	mhash_entries = simple_strtoul(str, &str, 0);
-	return 1;
+	return kstrtoul(str, 0, &mhash_entries) == 0;
 }
 __setup("mhash_entries=", set_mhash_entries);

I'm not very experienced with the cmdline option parsing but AFAICT the 'str' argument can be indeed NULL and kstrtoul() will not be happy with that?

Quoted 2 lines

I don't think 'str' can be NULL. If you don't pass a value, 'str' will be the empty string (just tested this).

Ah, ok. The NULL value can happen only for early parameters and for arguments without '=' sign in the name. So I'm retracting my objection and feel free to add:

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#4 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

Replace simple_strtoul() with the recommended kstrtoul() for parsing the 'mhash_entries=' and 'mphash_entries=' boot parameters.

Check the return value of kstrtoul() and reject invalid values. This adds error handling while preserving behavior for existing values, and removes use of the deprecated simple_strtoul() helper.

[...]

Applied to the vfs-7.0.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.0.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.0.misc

[1/1] namespace: Replace simple_strtoul with kstrtoul to parse boot params

      https://git.kernel.org/vfs/vfs/c/3f320e5c2eca