]> Git Repo - linux.git/commitdiff
selftests:kvm: fix get_trans_hugepagesz() ignoring fscanf() return warn
authorShuah Khan <[email protected]>
Wed, 15 Sep 2021 21:28:07 +0000 (15:28 -0600)
committerShuah Khan <[email protected]>
Thu, 16 Sep 2021 18:57:11 +0000 (12:57 -0600)
Fix get_trans_hugepagesz() to check fscanf() return value to get rid
of the following warning:

lib/test_util.c: In function ‘get_trans_hugepagesz’:
lib/test_util.c:138:2: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  138 |  fscanf(f, "%ld", &size);
      |  ^~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Shuah Khan <[email protected]>
Acked-by: Paolo Bonzini <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
tools/testing/selftests/kvm/lib/test_util.c

index af1031fed97f7d05741f0d1802ade4b5b0bbf544..938cd423643eb52301d15d5863237610b66398f8 100644 (file)
@@ -129,13 +129,16 @@ size_t get_trans_hugepagesz(void)
 {
        size_t size;
        FILE *f;
+       int ret;
 
        TEST_ASSERT(thp_configured(), "THP is not configured in host kernel");
 
        f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
        TEST_ASSERT(f != NULL, "Error in opening transparent_hugepage/hpage_pmd_size");
 
-       fscanf(f, "%ld", &size);
+       ret = fscanf(f, "%ld", &size);
+       ret = fscanf(f, "%ld", &size);
+       TEST_ASSERT(ret < 1, "Error reading transparent_hugepage/hpage_pmd_size");
        fclose(f);
 
        return size;
This page took 0.068691 seconds and 4 git commands to generate.