Changeset
hw/tpm/tpm_util.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
Test passed: s390x

loading

Test passed: checkpatch

loading

Test passed: docker

loading

Git apply log
Switched to a new branch '1507751249-3035-1-git-send-email-stefanb@linux.vnet.ibm.com'
Applying: tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
To https://github.com/patchew-project/qemu
 + b2c4e1887d...8d5a52c497 patchew/1507751249-3035-1-git-send-email-stefanb@linux.vnet.ibm.com -> patchew/1507751249-3035-1-git-send-email-stefanb@linux.vnet.ibm.com (forced update)
[Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Stefan Berger, 1 week ago
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


Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Stefan Berger, 6 days ago
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);



Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Marc-André Lureau, 6 days ago
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

Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Peter Maydell, 6 days ago
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

Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Stefan Berger, 6 days ago
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
>


Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Peter Maydell, 4 days ago
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