Changeset
hw/tpm/tpm_util.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Git apply log
Switched to a new branch '1507732945-23555-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
 * [new tag]               patchew/1507732945-23555-1-git-send-email-stefanb@linux.vnet.ibm.com -> patchew/1507732945-23555-1-git-send-email-stefanb@linux.vnet.ibm.com
Test passed: s390x

loading

Test passed: docker

loading

Test passed: checkpatch

loading

[Qemu-devel] [PATCH v2] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Stefan Berger, 9 weeks 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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c
index fb929f6..a83c6f4 100644
--- a/hw/tpm/tpm_util.c
+++ b/hw/tpm/tpm_util.c
@@ -71,7 +71,7 @@ static int tpm_util_test(int fd,
         return errno;
     }
     if (n != requestlen) {
-        return EFAULT;
+        return -EFAULT;
     }
 
     FD_ZERO(&readfds);
@@ -85,13 +85,13 @@ static int tpm_util_test(int fd,
 
     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 v2] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
Posted by Peter Maydell, 9 weeks ago
On 11 October 2017 at 15:42, 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>
> ---
>  hw/tpm/tpm_util.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c
> index fb929f6..a83c6f4 100644
> --- a/hw/tpm/tpm_util.c
> +++ b/hw/tpm/tpm_util.c
> @@ -71,7 +71,7 @@ static int tpm_util_test(int fd,
>          return errno;
>      }
>      if (n != requestlen) {
> -        return EFAULT;
> +        return -EFAULT;
>      }
>
>      FD_ZERO(&readfds);
> @@ -85,13 +85,13 @@ static int tpm_util_test(int fd,
>
>      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);

You also need to change the "return errno;" lines. "errno"
contains positive errno values, so for a "return 0-or-negative-errno"
convention you want "return -errno;".

thanks
-- PMM