[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to comp
From: |
Marc-André Lureau |
Subject: |
Re: [Qemu-devel] [PATCH v3] tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD |
Date: |
Fri, 13 Oct 2017 13:14:35 +0200 |
Hi
On Wed, Oct 11, 2017 at 9:47 PM, Stefan Berger
<address@hidden> 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 <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
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