KVM: selftests: Close opened file descriptor in stable_tsc_check_supported()
authorHao Ge <gehao@kylinos.cn>
Wed, 5 Apr 2023 10:13:50 +0000 (18:13 +0800)
committerSean Christopherson <seanjc@google.com>
Thu, 6 Apr 2023 00:02:49 +0000 (17:02 -0700)
Close the "current_clocksource" file descriptor before returning or exiting
from stable_tsc_check_supported() in vmx_nested_tsc_scaling_test.

Signed-off-by: Hao Ge <gehao@kylinos.cn>
Reviewed-by: Vipin Sharma <vipinsh@google.com>
Link: https://lore.kernel.org/r/20230405101350.259000-1-gehao@kylinos.cn
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c

index d427eb146bc5818e8d96a93da7c00a1b485bcf81..fa03c8d1ce4edb1d38a9be4aa4a7e60ea68f65a5 100644 (file)
@@ -126,12 +126,16 @@ static void stable_tsc_check_supported(void)
                goto skip_test;
 
        if (fgets(buf, sizeof(buf), fp) == NULL)
-               goto skip_test;
+               goto close_fp;
 
        if (strncmp(buf, "tsc", sizeof(buf)))
-               goto skip_test;
+               goto close_fp;
 
+       fclose(fp);
        return;
+
+close_fp:
+       fclose(fp);
 skip_test:
        print_skip("Kernel does not use TSC clocksource - assuming that host TSC is not stable");
        exit(KSFT_SKIP);