Skip to contentSkip to conversation

tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD

PATCH Superseded Stefan Berger 2 participants 2 messages Oct 11, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD

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.

---
 hw/tpm/tpm_util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/tpm/tpm_util.c +3 -3
index fb929f6..a83c6f4 100644
@@ -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);
Signature · 1 line
2.5.5
#1 lore raw
Quoted 32 lines · 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.

---
 hw/tpm/tpm_util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/tpm/tpm_util.c +2 -2
index fb929f6..a83c6f4 100644
@@ -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;

hw/tpm/tpm_util.c static int tpm_util_test(int fd, · line 97

Quoted 10 lines
hw/tpm/tpm_util.c +1 -1
     }
 
     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