This reworks setup_transparent_hugepage() to used the declared arrays (enabled_{strings,bits}[]). Signed-off-by: Gavin Shan <gshan@xxxxxxxxxx> --- mm/huge_memory.c | 49 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 26b47ce8ea17..228349f4f937 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -159,7 +159,6 @@ static struct shrinker huge_zero_page_shrinker = { .seeks = DEFAULT_SEEKS, }; -#ifdef CONFIG_SYSFS static const char * const enabled_strings[] = { "always", "madvise", "never" }; @@ -169,6 +168,7 @@ static unsigned int enabled_bits[] = { UINT_MAX }; +#ifdef CONFIG_SYSFS static ssize_t enabled_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -495,32 +495,31 @@ subsys_initcall(hugepage_init); static int __init setup_transparent_hugepage(char *str) { - int ret = 0; + int i; + if (!str) - goto out; - if (!strcmp(str, "always")) { - set_bit(TRANSPARENT_HUGEPAGE_FLAG, - &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, - &transparent_hugepage_flags); - ret = 1; - } else if (!strcmp(str, "madvise")) { - clear_bit(TRANSPARENT_HUGEPAGE_FLAG, - &transparent_hugepage_flags); - set_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, - &transparent_hugepage_flags); - ret = 1; - } else if (!strcmp(str, "never")) { - clear_bit(TRANSPARENT_HUGEPAGE_FLAG, - &transparent_hugepage_flags); - clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, - &transparent_hugepage_flags); - ret = 1; + goto error; + + for (i = 0; i < ARRAY_SIZE(enabled_strings); i++) { + if (!strcmp(str, enabled_strings[i])) + break; } -out: - if (!ret) - pr_warn("transparent_hugepage= cannot parse, ignored\n"); - return ret; + + if (i >= ARRAY_SIZE(enabled_strings)) + goto error; + + clear_bit(TRANSPARENT_HUGEPAGE_FLAG, + &transparent_hugepage_flags); + clear_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, + &transparent_hugepage_flags); + if (enabled_bits[i] != UINT_MAX) + set_bit(enabled_bits[i], &transparent_hugepage_flags); + + return 1; + +error: + pr_warn("transparent_hugepage= cannot parse, ignored\n"); + return 0; } __setup("transparent_hugepage=", setup_transparent_hugepage); -- 2.23.0