From: chenlifu <chenlifu@huawei.com>
To: <pbonzini@redhat.com>, <shuah@kernel.org>, <bgardon@google.com>,
<wangyanan55@huawei.com>, <axelrasmussen@google.com>,
<drjones@redhat.com>, <seanjc@google.com>, <vkuznets@redhat.com>,
<dwmw@amazon.co.uk>, <joao.m.martins@oracle.com>,
<yangyingliang@huawei.com>, <kvm@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: ping//Re: [PATCH -next 2/2] selftests: Fix fscanf warning
Date: Fri, 13 Aug 2021 15:27:32 +0800 [thread overview]
Message-ID: <fc55348e-566e-4684-0861-fa86a32c36f7@huawei.com> (raw)
In-Reply-To: <20210709063741.355325-2-chenlifu@huawei.com>
在 2021/7/9 14:37, Chen Lifu 写道:
> Compile selftests occurs the following warnings:
> make -C tools/testing/selftests
> ...
>
> 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);
> | ^~~~~~~~~~~~~~~~~~~~~~~
> x86_64/mmio_warning_test.c: In function ‘get_warnings_count’:
> x86_64/mmio_warning_test.c:85:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
> 85 | fscanf(f, "%d", &warnings);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~
> x86_64/xen_shinfo_test.c: In function ‘get_run_delay’:
> x86_64/xen_shinfo_test.c:109:9: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
> 109 | fscanf(fp, "%ld %ld ", &val[0], &val[1]);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> steal_time.c: In function ‘get_run_delay’:
> steal_time.c:228:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
> 228 | fscanf(fp, "%ld %ld ", &val[0], &val[1]);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Check the return value of ‘fscanf’ to fix it.
>
> Signed-off-by: Chen Lifu <chenlifu@huawei.com>
> ---
> tools/testing/selftests/kvm/lib/test_util.c | 3 ++-
> tools/testing/selftests/kvm/steal_time.c | 3 ++-
> tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 3 ++-
> tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c | 3 ++-
> 4 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> index af1031fed97f..02ed0d5c3aa5 100644
> --- a/tools/testing/selftests/kvm/lib/test_util.c
> +++ b/tools/testing/selftests/kvm/lib/test_util.c
> @@ -135,7 +135,8 @@ size_t get_trans_hugepagesz(void)
> 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);
> + if (fscanf(f, "%ld", &size) != 1)
> + size = 0;
> fclose(f);
>
> return size;
> diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> index b0031f2d38fd..18f231c45a12 100644
> --- a/tools/testing/selftests/kvm/steal_time.c
> +++ b/tools/testing/selftests/kvm/steal_time.c
> @@ -225,7 +225,8 @@ static 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]);
> + if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
> + val[1] = 0;
> fclose(fp);
>
> return val[1];
> diff --git a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
> index e6480fd5c4bd..e770037e5cc9 100644
> --- a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
> @@ -82,7 +82,8 @@ int get_warnings_count(void)
> FILE *f;
>
> f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
> - fscanf(f, "%d", &warnings);
> + if (fscanf(f, "%d", &warnings) != 1)
> + warnings = 0;
> fclose(f);
>
> return warnings;
> diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
> index 117bf49a3d79..6efda86083f1 100644
> --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
> @@ -106,7 +106,8 @@ static 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]);
> + if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
> + val[1] = 0;
> fclose(fp);
>
> return val[1];
>
next prev parent reply other threads:[~2021-08-13 7:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-09 6:37 [PATCH -next 1/2] selftests: Fix vm_handle_exception undefined error Chen Lifu
2021-07-09 6:37 ` [PATCH -next 2/2] selftests: Fix fscanf warning Chen Lifu
2021-08-13 7:27 ` chenlifu [this message]
2021-08-13 17:01 ` [PATCH -next 1/2] selftests: Fix vm_handle_exception undefined error Shuah Khan
2021-08-13 23:26 ` Paolo Bonzini
2021-08-16 2:53 ` chenlifu
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=fc55348e-566e-4684-0861-fa86a32c36f7@huawei.com \
--to=chenlifu@huawei.com \
--cc=axelrasmussen@google.com \
--cc=bgardon@google.com \
--cc=drjones@redhat.com \
--cc=dwmw@amazon.co.uk \
--cc=joao.m.martins@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vkuznets@redhat.com \
--cc=wangyanan55@huawei.com \
--cc=yangyingliang@huawei.com \
/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®