mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist
PATCH 1/1 mm/mm_init: Replace simple_strtoul with kstrtobool in set_hashdist
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".
--- include/linux/memblock.h | 4 ++-- mm/mm_init.c | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-)
include/linux/memblock.h +2 -2
@@ -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
mm/mm_init.c +3 -6
@@ -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 ) {}
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Quoted 11 lines · Thorsten Blum
Use bool for 'hashdist' and replace
simple_strtoul()withkstrtobool()for parsing the 'hashdist=' boot parameter. Unlikesimple_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 deprecatedsimple_strtoul()helper. The current code silently sets 'hashdist = 0' if parsing fails, instead of leaving the default value (HASHDIST_DEFAULT) unchanged.
Quoted 4 lines
Additionally,
kstrtobool()accepts common boolean strings such as "on" and "off".Signed-off-by Thorsten Blum <[email protected]>
Quoted 11 lines · Thorsten Blum
Use bool for 'hashdist' and replace
simple_strtoul()withkstrtobool()for parsing the 'hashdist=' boot parameter. Unlikesimple_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 deprecatedsimple_strtoul()helper. The current code silently sets 'hashdist = 0' if parsing fails, instead of leaving the default value (HASHDIST_DEFAULT) unchanged.
Quoted 4 lines
Additionally,
kstrtobool()accepts common boolean strings such as "on" and "off".Signed-off-by Thorsten Blum <[email protected]>
Quoted 4 lines
--- include/linux/memblock.h | 4 ++-- mm/mm_init.c | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-)
Signature · 2 lines
Sincerely yours, Mike.