From: Shuah Khan <skhan@linuxfoundation.org>
To: pbonzini@redhat.com, shuah@kernel.org
Cc: Shuah Khan <skhan@linuxfoundation.org>,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] selftests: kvm: fix get_run_delay() ignoring fscanf() return warn
Date: Wed, 15 Sep 2021 15:28:09 -0600 [thread overview]
Message-ID: <b93a1779df180a61e765bb67be7a83600585901c.1631737524.git.skhan@linuxfoundation.org> (raw)
In-Reply-To: <cover.1631737524.git.skhan@linuxfoundation.org>
Fix get_run_delay() to check fscanf() return value to get rid of the
following warning. When fscanf() fails return MIN_RUN_DELAY_NS from
get_run_delay(). Move MIN_RUN_DELAY_NS from steal_time.c to test_util.h
so get_run_delay() and steal_time.c can use it.
lib/test_util.c: In function ‘get_run_delay’:
lib/test_util.c:316:2: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
316 | fscanf(fp, "%ld %ld ", &val[0], &val[1]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
tools/testing/selftests/kvm/include/test_util.h | 2 ++
tools/testing/selftests/kvm/lib/test_util.c | 4 +++-
tools/testing/selftests/kvm/steal_time.c | 1 -
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index c7409b9b4e5b..451fed5ce8e7 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -95,6 +95,8 @@ struct vm_mem_backing_src_alias {
uint32_t flag;
};
+#define MIN_RUN_DELAY_NS 200000UL
+
bool thp_configured(void);
size_t get_trans_hugepagesz(void);
size_t get_def_hugetlb_pagesz(void);
diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
index f80dd38a38b2..a9107bfae402 100644
--- a/tools/testing/selftests/kvm/lib/test_util.c
+++ b/tools/testing/selftests/kvm/lib/test_util.c
@@ -313,7 +313,9 @@ long get_run_delay(void)
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
fp = fopen(path, "r");
- fscanf(fp, "%ld %ld ", &val[0], &val[1]);
+ /* Return MIN_RUN_DELAY_NS upon failure just to be safe */
+ if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) < 2)
+ val[1] = MIN_RUN_DELAY_NS;
fclose(fp);
return val[1];
diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index 51fe95a5c36a..2172d65b85e4 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -19,7 +19,6 @@
#define NR_VCPUS 4
#define ST_GPA_BASE (1 << 30)
-#define MIN_RUN_DELAY_NS 200000UL
static void *st_gva[NR_VCPUS];
static uint64_t guest_stolen_time[NR_VCPUS];
--
2.30.2
next prev parent reply other threads:[~2021-09-15 21:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-15 21:28 [PATCH 0/4] selftests: kvm: fscanf warn fixes and cleanups Shuah Khan
2021-09-15 21:28 ` [PATCH 1/4] selftests:kvm: fix get_warnings_count() ignoring fscanf() return warn Shuah Khan
2021-09-15 21:28 ` [PATCH 2/4] selftests:kvm: fix get_trans_hugepagesz() " Shuah Khan
2021-09-15 21:28 ` [PATCH 3/4] selftests: kvm: move get_run_delay() into lib/test_util Shuah Khan
2021-09-15 21:28 ` Shuah Khan [this message]
2021-09-15 22:34 ` [PATCH 0/4] selftests: kvm: fscanf warn fixes and cleanups Paolo Bonzini
2021-09-16 0:02 ` Shuah Khan
2021-09-16 5:06 ` Paolo Bonzini
2021-09-16 18:31 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b93a1779df180a61e765bb67be7a83600585901c.1631737524.git.skhan@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®