* [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
@ 2017-10-11 19:47 Stefan Berger
2017-10-13 11:09 ` Stefan Berger
2017-10-13 11:14 ` Marc-André Lureau
0 siblings, 2 replies; 6+ messages in thread
From: Stefan Berger @ 2017-10-11 19:47 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, amarnath.valluri, marcandre.lureau, Stefan Berger
EBADMSG was only added to OpenBSD very recently. To make QEMU compilable
on older OpenBSD versions use EMSGSIZE instead when a mismatch between
number of received bytes and message size indicated in the header was
found.
Return -EMSGSIZE and convert all other errnos in the same functions to
return the negative errno.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
hw/tpm/tpm_util.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c
index fb929f6..73d7796 100644
--- a/hw/tpm/tpm_util.c
+++ b/hw/tpm/tpm_util.c
@@ -68,10 +68,10 @@ static int tpm_util_test(int fd,
n = write(fd, request, requestlen);
if (n < 0) {
- return errno;
+ return -errno;
}
if (n != requestlen) {
- return EFAULT;
+ return -EFAULT;
}
FD_ZERO(&readfds);
@@ -80,18 +80,18 @@ static int tpm_util_test(int fd,
/* wait for a second */
n = select(fd + 1, &readfds, NULL, NULL, &tv);
if (n != 1) {
- return errno;
+ return -errno;
}
n = read(fd, &buf, sizeof(buf));
if (n < sizeof(struct tpm_resp_hdr)) {
- return EFAULT;
+ return -EFAULT;
}
resp = (struct tpm_resp_hdr *)buf;
/* check the header */
if (be32_to_cpu(resp->len) != n) {
- return EBADMSG;
+ return -EMSGSIZE;
}
*return_tag = be16_to_cpu(resp->tag);
--
2.5.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
2017-10-11 19:47 [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD Stefan Berger
@ 2017-10-13 11:09 ` Stefan Berger
2017-10-13 11:14 ` Marc-André Lureau
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Berger @ 2017-10-13 11:09 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, amarnath.valluri, marcandre.lureau
On 10/11/2017 03:47 PM, Stefan Berger wrote:
> EBADMSG was only added to OpenBSD very recently. To make QEMU compilable
> on older OpenBSD versions use EMSGSIZE instead when a mismatch between
> number of received bytes and message size indicated in the header was
> found.
>
> Return -EMSGSIZE and convert all other errnos in the same functions to
> return the negative errno.
>
> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Can someone have a look at this, please?
Stefan
> ---
> hw/tpm/tpm_util.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c
> index fb929f6..73d7796 100644
> --- a/hw/tpm/tpm_util.c
> +++ b/hw/tpm/tpm_util.c
> @@ -68,10 +68,10 @@ static int tpm_util_test(int fd,
>
> n = write(fd, request, requestlen);
> if (n < 0) {
> - return errno;
> + return -errno;
> }
> if (n != requestlen) {
> - return EFAULT;
> + return -EFAULT;
> }
>
> FD_ZERO(&readfds);
> @@ -80,18 +80,18 @@ static int tpm_util_test(int fd,
> /* wait for a second */
> n = select(fd + 1, &readfds, NULL, NULL, &tv);
> if (n != 1) {
> - return errno;
> + return -errno;
> }
>
> n = read(fd, &buf, sizeof(buf));
> if (n < sizeof(struct tpm_resp_hdr)) {
> - return EFAULT;
> + return -EFAULT;
> }
>
> resp = (struct tpm_resp_hdr *)buf;
> /* check the header */
> if (be32_to_cpu(resp->len) != n) {
> - return EBADMSG;
> + return -EMSGSIZE;
> }
>
> *return_tag = be16_to_cpu(resp->tag);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
2017-10-11 19:47 [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD Stefan Berger
2017-10-13 11:09 ` Stefan Berger
@ 2017-10-13 11:14 ` Marc-André Lureau
2017-10-13 16:12 ` Peter Maydell
1 sibling, 1 reply; 6+ messages in thread
From: Marc-André Lureau @ 2017-10-13 11:14 UTC (permalink / raw)
To: Stefan Berger; +Cc: QEMU, Peter Maydell, Amarnath Valluri
Hi
On Wed, Oct 11, 2017 at 9:47 PM, Stefan Berger
<stefanb@linux.vnet.ibm.com> wrote:
> EBADMSG was only added to OpenBSD very recently. To make QEMU compilable
> on older OpenBSD versions use EMSGSIZE instead when a mismatch between
> number of received bytes and message size indicated in the header was
> found.
>
> Return -EMSGSIZE and convert all other errnos in the same functions to
> return the negative errno.
>
> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Looks good to me,
but given that the return value isn't used, perhaps you could have
changed the function to return a bool success instead?
> ---
> hw/tpm/tpm_util.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c
> index fb929f6..73d7796 100644
> --- a/hw/tpm/tpm_util.c
> +++ b/hw/tpm/tpm_util.c
> @@ -68,10 +68,10 @@ static int tpm_util_test(int fd,
>
> n = write(fd, request, requestlen);
> if (n < 0) {
> - return errno;
> + return -errno;
> }
> if (n != requestlen) {
> - return EFAULT;
> + return -EFAULT;
> }
>
> FD_ZERO(&readfds);
> @@ -80,18 +80,18 @@ static int tpm_util_test(int fd,
> /* wait for a second */
> n = select(fd + 1, &readfds, NULL, NULL, &tv);
> if (n != 1) {
> - return errno;
> + return -errno;
> }
>
> n = read(fd, &buf, sizeof(buf));
> if (n < sizeof(struct tpm_resp_hdr)) {
> - return EFAULT;
> + return -EFAULT;
> }
>
> resp = (struct tpm_resp_hdr *)buf;
> /* check the header */
> if (be32_to_cpu(resp->len) != n) {
> - return EBADMSG;
> + return -EMSGSIZE;
> }
>
> *return_tag = be16_to_cpu(resp->tag);
> --
> 2.5.5
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
2017-10-13 11:14 ` Marc-André Lureau
@ 2017-10-13 16:12 ` Peter Maydell
2017-10-13 16:36 ` Stefan Berger
0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2017-10-13 16:12 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: Stefan Berger, QEMU, Amarnath Valluri
On 13 October 2017 at 12:14, Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
> Hi
>
> On Wed, Oct 11, 2017 at 9:47 PM, Stefan Berger
> <stefanb@linux.vnet.ibm.com> wrote:
>> EBADMSG was only added to OpenBSD very recently. To make QEMU compilable
>> on older OpenBSD versions use EMSGSIZE instead when a mismatch between
>> number of received bytes and message size indicated in the header was
>> found.
>>
>> Return -EMSGSIZE and convert all other errnos in the same functions to
>> return the negative errno.
>>
>> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>
> Looks good to me,
> but given that the return value isn't used, perhaps you could have
> changed the function to return a bool success instead?
AIUI this is just test code, so we probably don't gain too much
from extensively bikeshedding it. (Having said that, I can't
resist asking why it's not in tests/ :-))
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
2017-10-13 16:12 ` Peter Maydell
@ 2017-10-13 16:36 ` Stefan Berger
2017-10-15 16:49 ` Peter Maydell
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Berger @ 2017-10-13 16:36 UTC (permalink / raw)
To: Peter Maydell, Marc-André Lureau; +Cc: Amarnath Valluri, QEMU
On 10/13/2017 12:12 PM, Peter Maydell wrote:
> On 13 October 2017 at 12:14, Marc-André Lureau
> <marcandre.lureau@gmail.com> wrote:
>> Hi
>>
>> On Wed, Oct 11, 2017 at 9:47 PM, Stefan Berger
>> <stefanb@linux.vnet.ibm.com> wrote:
>>> EBADMSG was only added to OpenBSD very recently. To make QEMU compilable
>>> on older OpenBSD versions use EMSGSIZE instead when a mismatch between
>>> number of received bytes and message size indicated in the header was
>>> found.
>>>
>>> Return -EMSGSIZE and convert all other errnos in the same functions to
>>> return the negative errno.
>>>
>>> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
>> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>>
>> Looks good to me,
>> but given that the return value isn't used, perhaps you could have
>> changed the function to return a bool success instead?
> AIUI this is just test code, so we probably don't gain too much
> from extensively bikeshedding it. (Having said that, I can't
> resist asking why it's not in tests/ :-))
This is NOT test code. It's determining whether the external TPM is a
TPM 1.2 or TPM 2 emulation. This avoids having to start QEMU with a
'--tpm2' parmeter equivalent as well as the external emulator. Passing
this to the external emulator is enough.
Stefan
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
2017-10-13 16:36 ` Stefan Berger
@ 2017-10-15 16:49 ` Peter Maydell
0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2017-10-15 16:49 UTC (permalink / raw)
To: Stefan Berger; +Cc: Marc-André Lureau, Amarnath Valluri, QEMU
On 13 October 2017 at 17:36, Stefan Berger <stefanb@linux.vnet.ibm.com> wrote:
> This is NOT test code. It's determining whether the external TPM is a TPM
> 1.2 or TPM 2 emulation. This avoids having to start QEMU with a '--tpm2'
> parmeter equivalent as well as the external emulator. Passing this to the
> external emulator is enough.
Sorry -- I was misled by the way the function is named
"tpm_util_test()" and the comment in front of it says
"A basic test of a TPM device".
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-10-15 16:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-11 19:47 [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD Stefan Berger
2017-10-13 11:09 ` Stefan Berger
2017-10-13 11:14 ` Marc-André Lureau
2017-10-13 16:12 ` Peter Maydell
2017-10-13 16:36 ` Stefan Berger
2017-10-15 16:49 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).