From ffc8005a002ecc6f0d70675f7dee79cd481acffc Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Mon, 4 Jun 2018 14:11:48 +0200 Subject: [PATCH] ksm05: Fix cleanup on mising KSM run sys file If /sys/kernel/mm/ksm/run is not present the cleanup will stil try to restore it's value and the test will fail with a warning: tst_test.c:980: INFO: Timeout per run is 0h 15m 00s ksm05.c:98: CONF: KSM configuration is not enabled safe_file_ops.c:238: WARN: Failed to open FILE '/sys/kernel/mm/ksm/run' at ksm05.c:110 This patch changes the test to attempt to restore the value only if we were able to read it first. Signed-off-by: Cyril Hrubis Reported-by: Naresh Kamboju --- testcases/kernel/mem/ksm/ksm05.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/mem/ksm/ksm05.c b/testcases/kernel/mem/ksm/ksm05.c index f3bfbf4fad3..0e7c9d8c941 100644 --- a/testcases/kernel/mem/ksm/ksm05.c +++ b/testcases/kernel/mem/ksm/ksm05.c @@ -52,7 +52,7 @@ #ifdef HAVE_MADV_MERGEABLE -static int ksm_run_orig; +static int ksm_run_orig = -1; static void sighandler(int sig); static void test_ksm(void) @@ -107,7 +107,8 @@ static void setup(void) static void cleanup(void) { /* restore /sys/kernel/mm/ksm/run value */ - FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig); + if (ksm_run_orig > 0) + FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig); } static struct tst_test test = {