tpm: Use EMSGSIZE instead of EBADMSG to compile on OpenBSD
PATCH v3 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/tpm/tpm_util.c +5 -5
@@ -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);
Signature · 1 line
2.5.5
Quoted 9 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
-EMSGSIZEand convert all other errnos in the same functions to return the negative errno.Signed-off-by Stefan Berger <[email protected]>
Can someone have a look at this, please?
Stefan
Quoted 43 lines
--- hw/tpm/tpm_util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)hw/tpm/tpm_util.c +5
-5@@ -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);
Hi
Quoted 9 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
-EMSGSIZEand convert all other errnos in the same functions to return the negative errno.Signed-off-by Stefan Berger <[email protected]>
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?
Quoted 46 lines
--- hw/tpm/tpm_util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)hw/tpm/tpm_util.c +5
-6@@ -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
Signature · 1 line
Marc-André Lureau
Quoted 12 lines · Marc-André Lureau
Hi
Quoted 8 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
-EMSGSIZEand convert all other errnos in the same functions to return the negative errno.
Quoted 8 lines
Quoted 1 line
Signed-off-by Stefan Berger <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>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
Quoted 18 lines · Peter Maydell
Quoted 16 lines · Marc-André Lureau
Hi
Quoted 9 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
-EMSGSIZEand convert all other errnos in the same functions to return the negative errno.Signed-off-by Stefan Berger <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>
Quoted 6 lines
Quoted 3 lines
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
Quoted 4 lines
thanks
-- PMM
Quoted 4 lines · Stefan Berger
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