From: David Hildenbrand <david@redhat.com>
To: Liu Jing <liujing@cmss.chinamobile.com>, borntraeger@linux.ibm.com
Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com,
pbonzini@redhat.com, shuah@kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests: kvm: Adds a judgment on the return value
Date: Mon, 21 Oct 2024 13:20:44 +0200 [thread overview]
Message-ID: <7213ebbd-49d1-422d-84f2-14b48a14ed82@redhat.com> (raw)
In-Reply-To: <20241021100644.3591-1-liujing@cmss.chinamobile.com>
Am 21.10.24 um 12:06 schrieb Liu Jing:
> The global variable errno is not recommended to be assigned,
Just curious: from where is that information?
Reading the man page:
"errno is defined by the ISO C standard to be a modifiable lvalue
of type int, and must not be explicitly declared; errno may be a
macro. errno is thread-local; setting it in one thread does not
affect its value in any other thread."
Paired with
"For some system calls and library functions (e.g.,
getpriority(2)), -1 is a valid return on success. In such cases,
a successful return can be distinguished from an error return by
setting errno to zero before the call"
Not objecting that relying on the rc looks cleaner.
> and rc in the function does not check its return value, so it is fixed
>
> Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
> ---
> tools/testing/selftests/kvm/s390x/cmma_test.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/s390x/cmma_test.c b/tools/testing/selftests/kvm/s390x/cmma_test.c
> index e32dd59703a0..c59c21f28bbd 100644
> --- a/tools/testing/selftests/kvm/s390x/cmma_test.c
> +++ b/tools/testing/selftests/kvm/s390x/cmma_test.c
> @@ -210,7 +210,7 @@ static int vm_get_cmma_bits(struct kvm_vm *vm, u64 flags, int *errno_out)
> struct kvm_s390_cmma_log args;
> int rc;
>
> - errno = 0;
> + *errno_out = 0;
>
> args = (struct kvm_s390_cmma_log){
> .start_gfn = 0,
> @@ -219,8 +219,10 @@ static int vm_get_cmma_bits(struct kvm_vm *vm, u64 flags, int *errno_out)
> .values = (__u64)&cmma_value_buf[0]
> };
> rc = __vm_ioctl(vm, KVM_S390_GET_CMMA_BITS, &args);
> + if (rc < 0) {
> + *errno_out = errno;
> + }
>
if (rc < 0)
*errno_out = errno;
--
Cheers,
David / dhildenb
prev parent reply other threads:[~2024-10-21 11:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 10:06 [PATCH] selftests: kvm: Adds a judgment on the return value Liu Jing
2024-10-21 11:20 ` David Hildenbrand [this message]
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=7213ebbd-49d1-422d-84f2-14b48a14ed82@redhat.com \
--to=david@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=liujing@cmss.chinamobile.com \
--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