mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-28 01:43:47 -04:00
selftests/mm: fix ternary operator precedence in ksm_tests
The KSM selftest uses conditional expressions to skip accesses to
merge_across_nodes on systems without NUMA support. However, the ternary
operator is combined with logical OR without parentheses:
a || numa_available() ? 0 : b || c
Due to operator precedence rules, this is parsed as:
(a || numa_available()) ? 0 : (b || c)
instead of the intended:
a || (numa_available() ? 0 : b) || c
Add parentheses around the conditional expressions to ensure the
correct evaluation order.
Link: https://lore.kernel.org/ce859430287ed2642848c933a90eb9a69da361f0.1783446924.git.sayalip@linux.ibm.com
Fixes: 9aa1af954d ("selftests: vm: check numa_available() before operating "merge_across_nodes" in ksm_tests")
Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Liam Howlett <liam@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
15828a150c
commit
4e1fbffb33
@@ -288,8 +288,8 @@ static bool assert_ksm_pages_count(long dupl_page_count)
|
||||
static int ksm_save_def(struct ksm_sysfs *ksm_sysfs)
|
||||
{
|
||||
if (ksm_read_sysfs(KSM_FP("max_page_sharing"), &ksm_sysfs->max_page_sharing) ||
|
||||
numa_available() ? 0 :
|
||||
ksm_read_sysfs(KSM_FP("merge_across_nodes"), &ksm_sysfs->merge_across_nodes) ||
|
||||
(numa_available() ? 0 :
|
||||
ksm_read_sysfs(KSM_FP("merge_across_nodes"), &ksm_sysfs->merge_across_nodes)) ||
|
||||
ksm_read_sysfs(KSM_FP("sleep_millisecs"), &ksm_sysfs->sleep_millisecs) ||
|
||||
ksm_read_sysfs(KSM_FP("pages_to_scan"), &ksm_sysfs->pages_to_scan) ||
|
||||
ksm_read_sysfs(KSM_FP("run"), &ksm_sysfs->run) ||
|
||||
@@ -304,8 +304,8 @@ static int ksm_save_def(struct ksm_sysfs *ksm_sysfs)
|
||||
static int ksm_restore(struct ksm_sysfs *ksm_sysfs)
|
||||
{
|
||||
if (ksm_write_sysfs(KSM_FP("max_page_sharing"), ksm_sysfs->max_page_sharing) ||
|
||||
numa_available() ? 0 :
|
||||
ksm_write_sysfs(KSM_FP("merge_across_nodes"), ksm_sysfs->merge_across_nodes) ||
|
||||
(numa_available() ? 0 :
|
||||
ksm_write_sysfs(KSM_FP("merge_across_nodes"), ksm_sysfs->merge_across_nodes)) ||
|
||||
ksm_write_sysfs(KSM_FP("pages_to_scan"), ksm_sysfs->pages_to_scan) ||
|
||||
ksm_write_sysfs(KSM_FP("run"), ksm_sysfs->run) ||
|
||||
ksm_write_sysfs(KSM_FP("sleep_millisecs"), ksm_sysfs->sleep_millisecs) ||
|
||||
@@ -846,8 +846,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (ksm_write_sysfs(KSM_FP("run"), 2) ||
|
||||
ksm_write_sysfs(KSM_FP("sleep_millisecs"), 0) ||
|
||||
numa_available() ? 0 :
|
||||
ksm_write_sysfs(KSM_FP("merge_across_nodes"), 1) ||
|
||||
(numa_available() ? 0 :
|
||||
ksm_write_sysfs(KSM_FP("merge_across_nodes"), 1)) ||
|
||||
ksm_write_sysfs(KSM_FP("pages_to_scan"), page_count))
|
||||
ksft_exit_fail_msg("Cannot set up KSM tunables\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user