From ab9633d581110a5da08bd2d2c7c070f3862fe9af Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 11 Aug 2015 18:23:15 +0100 Subject: [PATCH] core: add convenience macros to local.h Move ARRAY_SIZE() from tplg_local.h to local.h and add container_of() macro to local.h. Both macros are generic but are initially used by topology. Signed-off-by: Liam Girdwood Signed-off-by: Takashi Iwai --- include/local.h | 7 +++++++ src/topology/tplg_local.h | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/local.h b/include/local.h index 66008163..b429f5d0 100644 --- a/include/local.h +++ b/include/local.h @@ -350,4 +350,11 @@ int snd_config_search_alias_hooks(snd_config_t *config, int _snd_conf_generic_id(const char *id); +/* convenience macros */ +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + #endif diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h index febc1772..3982cc70 100644 --- a/src/topology/tplg_local.h +++ b/src/topology/tplg_local.h @@ -32,7 +32,6 @@ #define MAX_FILE 256 #define TPLG_MAX_PRIV_SIZE (1024 * 128) #define ALSA_TPLG_DIR ALSA_CONFIG_DIR "/topology" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) /** The name of the environment variable containing the tplg directory */ #define ALSA_CONFIG_TPLG_VAR "ALSA_CONFIG_TPLG" -- 2.47.1