Commit 6233471f authored by Muchun Song's avatar Muchun Song Committed by Zheng Zengkai
Browse files

mm: hugetlb_vmemmap: use kstrtobool for hugetlb_vmemmap param parsing

mainline inclusion
from mainline-v5.19-rc1
commit 9c54c522
category: feature
bugzilla: 187198, https://gitee.com/openeuler/kernel/issues/I5GVFO
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9c54c522bb76cbef480722bd44059e2ba8304bd2

--------------------------------

Use kstrtobool rather than open coding "on" and "off" parsing in
mm/hugetlb_vmemmap.c, which is more powerful to handle all kinds of
parameters like 'Yy1Nn0' or [oO][NnFf] for "on" and "off".

Link: https://lkml.kernel.org/r/20220512041142.39501-4-songmuchun@bytedance.com


Signed-off-by: default avatarMuchun Song <songmuchun@bytedance.com>
Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kees Cook <keescook@chromium.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Xiongchun Duan <duanxiongchun@bytedance.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 9e38aa2f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1597,10 +1597,10 @@
			enabled.
			Allows heavy hugetlb users to free up some more
			memory (7 * PAGE_SIZE for each 2MB hugetlb page).
			Format: { on | off (default) }
			Format: { [oO][Nn]/Y/y/1 | [oO][Ff]/N/n/0 (default) }

			on:  enable the feature
			off: disable the feature
			[oO][Nn]/Y/y/1: enable the feature
			[oO][Ff]/N/n/0: disable the feature

			Built with CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON=y,
			the default is on.
+5 −5
Original line number Diff line number Diff line
@@ -194,15 +194,15 @@ EXPORT_SYMBOL(hugetlb_optimize_vmemmap_key);

static int __init hugetlb_vmemmap_early_param(char *buf)
{
	if (!buf)
	bool enable;

	if (kstrtobool(buf, &enable))
		return -EINVAL;

	if (!strcmp(buf, "on"))
	if (enable)
		static_branch_enable(&hugetlb_optimize_vmemmap_key);
	else if (!strcmp(buf, "off"))
		static_branch_disable(&hugetlb_optimize_vmemmap_key);
	else
		return -EINVAL;
		static_branch_disable(&hugetlb_optimize_vmemmap_key);

	return 0;
}