Module Name:    src
Committed By:   riastradh
Date:           Sat Jan 29 12:27:30 UTC 2022

Modified Files:
        src/sys/dev/ic: tpm.c tpmreg.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/ic/tpm.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/ic/tpmreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/tpm.c
diff -u src/sys/dev/ic/tpm.c:1.24 src/sys/dev/ic/tpm.c:1.25
--- src/sys/dev/ic/tpm.c:1.24	Sun Jan 16 20:24:34 2022
+++ src/sys/dev/ic/tpm.c	Sat Jan 29 12:27:30 2022
@@ -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 @@ tpm12_suspend(struct tpm_softc *sc)
 	/*
 	 * 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 @@ tpm20_suspend(struct tpm_softc *sc)
 	/*
 	 * 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 @@ tpmread(dev_t dev, struct uio *uio, int 
 		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;

Index: src/sys/dev/ic/tpmreg.h
diff -u src/sys/dev/ic/tpmreg.h:1.10 src/sys/dev/ic/tpmreg.h:1.11
--- src/sys/dev/ic/tpmreg.h:1.10	Sun Nov 14 21:18:30 2021
+++ src/sys/dev/ic/tpmreg.h	Sat Jan 29 12:27:30 2022
@@ -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;

Reply via email to