topology: fix the unaligned access

Introduce unaligned_get32/put32 helpers to deal with the
packed structures.

Use the gcc __BYTE_ORDER__ defines for the endian checks.
It may be improved to support other compilation environment.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2020-08-31 14:27:26 +02:00
parent 84c6aeef5c
commit ab73253924
3 changed files with 29 additions and 16 deletions

View file

@ -225,6 +225,19 @@ struct tplg_table {
extern struct tplg_table tplg_table[];
extern unsigned int tplg_table_items;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_INT__ == 4
static inline unsigned int unaligned_get32(void *src)
{
unsigned int ret;
memcpy(&ret, src, sizeof(ret));
return ret;
}
static inline void unaligned_put32(void *dst, unsigned int val)
{
memcpy(dst, &val, sizeof(val));
}
#endif
#define tplg_log(tplg, type, pos, fmt, args...) do { \
if ((tplg)->verbose) \
tplg_log_((tplg), (type), (pos), (fmt), ##args); \