linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist
@ 2025-12-17 11:02 Thorsten Blum
  2025-12-18 20:52 ` Matthew Wilcox
  2025-12-19  6:48 ` Mike Rapoport
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2025-12-17 11:02 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton; +Cc: Thorsten Blum, linux-mm, linux-kernel

Use bool for 'hashdist' and replace simple_strtoul() with kstrtobool()
for parsing the 'hashdist=' boot parameter. Unlike simple_strtoul(),
which returns an unsigned long, kstrtobool() converts the string
directly to bool and avoids implicit casting.

Check the return value of kstrtobool() and reject invalid values. This
adds error handling while preserving behavior for existing values, and
removes use of the deprecated simple_strtoul() helper. The current code
silently sets 'hashdist = 0' if parsing fails, instead of leaving the
default value (HASHDIST_DEFAULT) unchanged.

Additionally, kstrtobool() accepts common boolean strings such as "on"
and "off".

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 include/linux/memblock.h | 4 ++--
 mm/mm_init.c             | 9 +++------
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 221118b5a16e..6ec5e9ac0699 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -598,9 +598,9 @@ extern void *alloc_large_system_hash(const char *tablename,
  */
 #ifdef CONFIG_NUMA
 #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT)
-extern int hashdist;		/* Distribute hashes across NUMA nodes? */
+extern bool hashdist;		/* Distribute hashes across NUMA nodes? */
 #else
-#define hashdist (0)
+#define hashdist (false)
 #endif
 
 #ifdef CONFIG_MEMTEST
diff --git a/mm/mm_init.c b/mm/mm_init.c
index fc2a6f1e518f..d86248566a56 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -646,21 +646,18 @@ int __meminit early_pfn_to_nid(unsigned long pfn)
 	return nid;
 }
 
-int hashdist = HASHDIST_DEFAULT;
+bool hashdist = HASHDIST_DEFAULT;
 
 static int __init set_hashdist(char *str)
 {
-	if (!str)
-		return 0;
-	hashdist = simple_strtoul(str, &str, 0);
-	return 1;
+	return kstrtobool(str, &hashdist) == 0;
 }
 __setup("hashdist=", set_hashdist);
 
 static inline void fixup_hashdist(void)
 {
 	if (num_node_state(N_MEMORY) == 1)
-		hashdist = 0;
+		hashdist = false;
 }
 #else
 static inline void fixup_hashdist(void) {}
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist
  2025-12-17 11:02 [PATCH] mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist Thorsten Blum
@ 2025-12-18 20:52 ` Matthew Wilcox
  2025-12-19  6:48 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2025-12-18 20:52 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: Mike Rapoport, Andrew Morton, linux-mm, linux-kernel

On Wed, Dec 17, 2025 at 12:02:13PM +0100, Thorsten Blum wrote:
> Use bool for 'hashdist' and replace simple_strtoul() with kstrtobool()
> for parsing the 'hashdist=' boot parameter. Unlike simple_strtoul(),
> which returns an unsigned long, kstrtobool() converts the string
> directly to bool and avoids implicit casting.
> 
> Check the return value of kstrtobool() and reject invalid values. This
> adds error handling while preserving behavior for existing values, and
> removes use of the deprecated simple_strtoul() helper. The current code
> silently sets 'hashdist = 0' if parsing fails, instead of leaving the
> default value (HASHDIST_DEFAULT) unchanged.
> 
> Additionally, kstrtobool() accepts common boolean strings such as "on"
> and "off".
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist
  2025-12-17 11:02 [PATCH] mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist Thorsten Blum
  2025-12-18 20:52 ` Matthew Wilcox
@ 2025-12-19  6:48 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2025-12-19  6:48 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: Andrew Morton, linux-mm, linux-kernel

On Wed, Dec 17, 2025 at 12:02:13PM +0100, Thorsten Blum wrote:
> Use bool for 'hashdist' and replace simple_strtoul() with kstrtobool()
> for parsing the 'hashdist=' boot parameter. Unlike simple_strtoul(),
> which returns an unsigned long, kstrtobool() converts the string
> directly to bool and avoids implicit casting.
> 
> Check the return value of kstrtobool() and reject invalid values. This
> adds error handling while preserving behavior for existing values, and
> removes use of the deprecated simple_strtoul() helper. The current code
> silently sets 'hashdist = 0' if parsing fails, instead of leaving the
> default value (HASHDIST_DEFAULT) unchanged.
> 
> Additionally, kstrtobool() accepts common boolean strings such as "on"
> and "off".
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> ---
>  include/linux/memblock.h | 4 ++--
>  mm/mm_init.c             | 9 +++------
>  2 files changed, 5 insertions(+), 8 deletions(-)

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-19  6:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-17 11:02 [PATCH] mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist Thorsten Blum
2025-12-18 20:52 ` Matthew Wilcox
2025-12-19  6:48 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox