Commit f5013d41 authored by Shuah Khan's avatar Shuah Khan

selftests: kvm: fix get_run_delay() ignoring fscanf() return warn

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: default avatarShuah Khan <skhan@linuxfoundation.org>
Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 20175d5e
...@@ -95,6 +95,8 @@ struct vm_mem_backing_src_alias { ...@@ -95,6 +95,8 @@ struct vm_mem_backing_src_alias {
uint32_t flag; uint32_t flag;
}; };
#define MIN_RUN_DELAY_NS 200000UL
bool thp_configured(void); bool thp_configured(void);
size_t get_trans_hugepagesz(void); size_t get_trans_hugepagesz(void);
size_t get_def_hugetlb_pagesz(void); size_t get_def_hugetlb_pagesz(void);
......
...@@ -313,7 +313,9 @@ long get_run_delay(void) ...@@ -313,7 +313,9 @@ long get_run_delay(void)
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid)); sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
fp = fopen(path, "r"); 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); fclose(fp);
return val[1]; return val[1];
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#define NR_VCPUS 4 #define NR_VCPUS 4
#define ST_GPA_BASE (1 << 30) #define ST_GPA_BASE (1 << 30)
#define MIN_RUN_DELAY_NS 200000UL
static void *st_gva[NR_VCPUS]; static void *st_gva[NR_VCPUS];
static uint64_t guest_stolen_time[NR_VCPUS]; static uint64_t guest_stolen_time[NR_VCPUS];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment