Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endi...



details:   https://anonhg.NetBSD.org/src/rev/48b386943b8d
branches:  trunk
changeset: 359882:48b386943b8d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Jan 29 12:27:30 2022 +0000

description:
tpm(4): Nix TPM_BE16/TPM_BE32.  Just use sys/endian.h.

diffstat:

 sys/dev/ic/tpm.c    |  30 +++++++++++++++---------------
 sys/dev/ic/tpmreg.h |  10 +---------
 2 files changed, 16 insertions(+), 24 deletions(-)

diffs (93 lines):

diff -r e4a4f61462cf -r 48b386943b8d sys/dev/ic/tpm.c
--- a/sys/dev/ic/tpm.c  Sat Jan 29 11:20:30 2022 +0000
+++ b/sys/dev/ic/tpm.c  Sat Jan 29 12:27:30 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tpm.c,v 1.24 2022/01/16 20:24:34 riastradh Exp $       */
+/*     $NetBSD: tpm.c,v 1.25 2022/01/29 12:27:30 riastradh Exp $       */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.24 2022/01/16 20:24:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.25 2022/01/29 12:27:30 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -205,14 +205,14 @@
        /*
         * Verify the response looks reasonable.
         */
-       if (TPM_BE16(response.tag) != TPM_TAG_RSP_COMMAND ||
-           TPM_BE32(response.length) != sizeof(response) ||
-           TPM_BE32(response.code) != 0) {
+       if (be16toh(response.tag) != TPM_TAG_RSP_COMMAND ||
+           be32toh(response.length) != sizeof(response) ||
+           be32toh(response.code) != 0) {
                device_printf(sc->sc_dev,
                    "TPM_ORD_SaveState failed: tag=0x%x length=0x%x code=0x%x",
-                   TPM_BE16(response.tag),
-                   TPM_BE32(response.length),
-                   TPM_BE32(response.code));
+                   be16toh(response.tag),
+                   be32toh(response.length),
+                   be32toh(response.code));
                error = EIO;
                goto out;
        }
@@ -303,14 +303,14 @@
        /*
         * Verify the response looks reasonable.
         */
-       if (TPM_BE16(response.tag) != TPM2_ST_NO_SESSIONS ||
-           TPM_BE32(response.length) != sizeof(response) ||
-           TPM_BE32(response.code) != TPM2_RC_SUCCESS) {
+       if (be16toh(response.tag) != TPM2_ST_NO_SESSIONS ||
+           be32toh(response.length) != sizeof(response) ||
+           be32toh(response.code) != TPM2_RC_SUCCESS) {
                device_printf(sc->sc_dev,
                    "TPM_CC_Shutdown failed: tag=0x%x length=0x%x code=0x%x",
-                   TPM_BE16(response.tag),
-                   TPM_BE32(response.length),
-                   TPM_BE32(response.code));
+                   be16toh(response.tag),
+                   be32toh(response.length),
+                   be32toh(response.code));
                error = EIO;
                goto out;
        }
@@ -1084,7 +1084,7 @@
                rv = EIO;
                goto out;
        }
-       len = TPM_BE32(hdr.length);
+       len = be32toh(hdr.length);
        if (len > MIN(sizeof(buf), uio->uio_resid) || len < sizeof(hdr)) {
                rv = EIO;
                goto out;
diff -r e4a4f61462cf -r 48b386943b8d sys/dev/ic/tpmreg.h
--- a/sys/dev/ic/tpmreg.h       Sat Jan 29 11:20:30 2022 +0000
+++ b/sys/dev/ic/tpmreg.h       Sat Jan 29 12:27:30 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tpmreg.h,v 1.10 2021/11/14 21:18:30 riastradh Exp $    */
+/*     $NetBSD: tpmreg.h,v 1.11 2022/01/29 12:27:30 riastradh Exp $    */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -37,14 +37,6 @@
 #include <sys/cdefs.h>
 #include <sys/endian.h>
 
-#if (_BYTE_ORDER == _LITTLE_ENDIAN)
-#define TPM_BE16(a)    bswap16(a)
-#define TPM_BE32(a)    bswap32(a)
-#else
-#define TPM_BE16(a)    (a)
-#define TPM_BE32(a)    (a)
-#endif
-
 struct tpm_header {
        uint16_t tag;
        uint32_t length;



Home | Main Index | Thread Index | Old Index