From 7a3814b0f063e0d85fb3e4226cbfc7d174a13c9b Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Fri, 23 Feb 2018 16:00:43 +1030 Subject: 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 --- common.c | 6 ++++-- 1 file 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)); } -- cgit v1.2.1