Skip to content

Commit f5013d4

Browse files
committed
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: Shuah Khan <[email protected]> Acked-by: Paolo Bonzini <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 20175d5 commit f5013d4

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

tools/testing/selftests/kvm/include/test_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct vm_mem_backing_src_alias {
9595
uint32_t flag;
9696
};
9797

98+
#define MIN_RUN_DELAY_NS 200000UL
99+
98100
bool thp_configured(void);
99101
size_t get_trans_hugepagesz(void);
100102
size_t get_def_hugetlb_pagesz(void);

tools/testing/selftests/kvm/lib/test_util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ long get_run_delay(void)
313313

314314
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
315315
fp = fopen(path, "r");
316-
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
316+
/* Return MIN_RUN_DELAY_NS upon failure just to be safe */
317+
if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) < 2)
318+
val[1] = MIN_RUN_DELAY_NS;
317319
fclose(fp);
318320

319321
return val[1];

tools/testing/selftests/kvm/steal_time.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#define NR_VCPUS 4
2121
#define ST_GPA_BASE (1 << 30)
22-
#define MIN_RUN_DELAY_NS 200000UL
2322

2423
static void *st_gva[NR_VCPUS];
2524
static uint64_t guest_stolen_time[NR_VCPUS];

0 commit comments

Comments
 (0)