Skip to contentSkip to conversation

KEYS: trusted: fix type warnings in ntohl/nthos

PATCH In review Ben Dooks (Codethink) 2 participants 3 messages Dec 17, 2019 – Dec 18, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KEYS: trusted: fix type warnings in ntohl/nthos

The ntohl takes a __be32 and ntohs takes __be16, so cast to those types before passing it to the byte swapping functions.

Note, would be32_to_cpu and be16_to_cpu be better here?

security/keys/trusted-keys/trusted_tpm1.c:201:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:201:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:201:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:201:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:201:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:201:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:202:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:202:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:202:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:202:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:289:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:289:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:289:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:289:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:289:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:289:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:290:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:290:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:290:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:290:15: warning: cast to restricted __be16 security/keys/trusted-keys/trusted_tpm1.c:418:21: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:418:21: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:418:21: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:418:21: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:418:21: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:418:21: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:442:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:442:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:442:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:442:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:442:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:442:19: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:549:24: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:549:24: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:549:24: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:549:24: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:549:24: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:549:24: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:550:23: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:550:23: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:550:23: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:550:23: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:550:23: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:550:23: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:602:17: warning: incorrect type in assignment (different base types)
security/keys/trusted-keys/trusted_tpm1.c:602:17: expected unsigned int [usertype] ordinal
security/keys/trusted-keys/trusted_tpm1.c:602:17: got restricted __be32 [usertype]
security/keys/trusted-keys/trusted_tpm1.c:638:20: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:638:20: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:638:20: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:638:20: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:638:20: warning: cast to restricted __be32 security/keys/trusted-keys/trusted_tpm1.c:638:20: warning: cast to restricted __be32

---
Cc: David Howells <[email protected]>
Cc: Jarkko Sakkinen <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 include/keys/trusted_tpm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/keys/trusted_tpm.h +2 -2
index a56d8e1298f2..e080967931d2 100644
@@ -12,9 +12,9 @@
 #define TPM_RETURN_OFFSET		6
 #define TPM_DATA_OFFSET			10
 
-#define LOAD32(buffer, offset)	(ntohl(*(uint32_t *)&buffer[offset]))
+#define LOAD32(buffer, offset)	(ntohl(*(__be32 *)&buffer[offset]))
 #define LOAD32N(buffer, offset)	(*(uint32_t *)&buffer[offset])
-#define LOAD16(buffer, offset)	(ntohs(*(uint16_t *)&buffer[offset]))
+#define LOAD16(buffer, offset)	(ntohs(*(__be16 *)&buffer[offset]))
 
 struct osapsess {
 	uint32_t handle;
Signature · 1 line
2.24.0
#1 lore raw
Quoted 2 lines · Ben Dooks (Codethink)

The ntohl takes a __be32 and ntohs takes __be16, so cast to those types before passing it to the byte swapping functions.

Thanks!

Quoted 1 line

Note, would be32_to_cpu and be16_to_cpu be better here?

Yes, I think that should work too.

/Jarkko

#2 lore raw
In reply to Ben Dooks (Codethink)
Quoted 4 lines · Ben Dooks (Codethink)

The ntohl takes a __be32 and ntohs takes __be16, so cast to those types before passing it to the byte swapping functions.

Note, would be32_to_cpu and be16_to_cpu be better here?

Yes, can you refine this?

Also in commit message you could

"
E.g.

security/keys/trusted-keys/trusted_tpm1.c:201:19: warning: cast to restricted __be32 "

We get the idea from one line :-)

/Jarkko