diff mbox series

[RESEND] selftest/vmx_nested_tsc_scaling_test: fix fp leak

Message ID 20230404032311.146506-1-gehao@kylinos.cn (mailing list archive)
State Accepted
Commit 7712145073876092e9aa81f0b836fef8b5694b14
Headers show
Series [RESEND] selftest/vmx_nested_tsc_scaling_test: fix fp leak | expand

Commit Message

Hao Ge April 4, 2023, 3:23 a.m. UTC
Fix stable_tsc_check_supported fopen but not fclose

Signed-off-by: Hao Ge <gehao@kylinos.cn>
---
 .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Vipin Sharma April 4, 2023, 4:59 p.m. UTC | #1
On Mon, Apr 3, 2023 at 8:24 PM Hao Ge <gehao@kylinos.cn> wrote:
>
> Fix stable_tsc_check_supported fopen but not fclose
>
> Signed-off-by: Hao Ge <gehao@kylinos.cn>

I will recommend to expand the commit log to something more descriptive like:

KVM: selftests: Close opened file descriptor in stable_tsc_check_supported()

Close the "current_clocksource" file descriptor before returning or
exiting from stable_tsc_check_supported() in
vmx_nested_tsc_scaling_test

> ---
>  .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c    | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
> index d427eb146bc5..fa03c8d1ce4e 100644
> --- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
> @@ -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);
> --

Other than commit log, Reviewed-by: Vipin Sharma <vipinsh@google.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
index d427eb146bc5..fa03c8d1ce4e 100644
--- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
+++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
@@ -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);