summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-02-23 16:00:43 +1030
committerAndrew Jeffery <andrew@aj.id.au>2018-03-19 10:55:20 +1030
commit7a3814b0f063e0d85fb3e4226cbfc7d174a13c9b (patch)
treea121d672d8052f8222ab722726819cf45326fffc
parentcafb002ebcbe8c9a828a1b3c15d2f9b95fb7e9ec (diff)
downloadphosphor-mboxd-7a3814b0f063e0d85fb3e4226cbfc7d174a13c9b.tar.gz
phosphor-mboxd-7a3814b0f063e0d85fb3e4226cbfc7d174a13c9b.zip
common: Ensure helpers are endian-safe
The specification states that all multibyte values communicated via mbox are little-endian[0]. Do the conversions in the helpers to enforce this property. [0] https://github.com/openbmc/mboxbridge/blob/master/Documentation/mbox_protocol.md#information Change-Id: I9f96281c439fd666cb1c9ae643454569d61f7a81 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
-rw-r--r--common.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/common.c b/common.c
index b562cc9..c460815 100644
--- a/common.c
+++ b/common.c
@@ -54,21 +54,23 @@ void mbox_log(int p, const char *fmt, ...)
uint16_t get_u16(uint8_t *ptr)
{
- return *(uint16_t *)ptr;
+ return le16toh(*(uint16_t *)ptr);
}
void put_u16(uint8_t *ptr, uint16_t val)
{
+ val = htole16(val);
memcpy(ptr, &val, sizeof(val));
}
uint32_t get_u32(uint8_t *ptr)
{
- return *(uint32_t *)ptr;
+ return le32toh(*(uint32_t *)ptr);
}
void put_u32(uint8_t *ptr, uint32_t val)
{
+ val = htole32(val);
memcpy(ptr, &val, sizeof(val));
}
OpenPOWER on IntegriCloud