From 24089e04cb1b4975bafd6368ab8b92082ebf6ad7 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 18 May 2014 14:24:12 +0200 Subject: ASoC: Add helper functions to cast from DAPM context to CODEC/platform This is useful if we have a pointer to a DAPM context and know that it is a CODEC or platform DAPM context and want to get a pointer to the CODEC or platform. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown diff --git a/include/sound/soc.h b/include/sound/soc.h index b9ee220..520b668 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1135,6 +1135,33 @@ static inline struct snd_soc_platform *snd_soc_component_to_platform( return container_of(component, struct snd_soc_platform, component); } +/** + * snd_soc_dapm_to_codec() - Casts a DAPM context to the CODEC it is embedded in + * @dapm: The DAPM context to cast to the CODEC + * + * This function must only be used on DAPM contexts that are known to be part of + * a CODEC (e.g. in a CODEC driver). Otherwise the behavior is undefined. + */ +static inline struct snd_soc_codec *snd_soc_dapm_to_codec( + struct snd_soc_dapm_context *dapm) +{ + return container_of(dapm, struct snd_soc_codec, dapm); +} + +/** + * snd_soc_dapm_to_platform() - Casts a DAPM context to the platform it is + * embedded in + * @dapm: The DAPM context to cast to the platform. + * + * This function must only be used on DAPM contexts that are known to be part of + * a platform (e.g. in a platform driver). Otherwise the behavior is undefined. + */ +static inline struct snd_soc_platform *snd_soc_dapm_to_platform( + struct snd_soc_dapm_context *dapm) +{ + return container_of(dapm, struct snd_soc_platform, dapm); +} + /* codec IO */ unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg, -- cgit v0.10.2 From b59dce53ef6193139253db09bfb64e3834689f1b Mon Sep 17 00:00:00 2001 From: Xiubo Li Date: Mon, 19 May 2014 16:32:09 +0800 Subject: ASoC: cache: Fix possible ZERO_SIZE_PTR pointer dereferencing error. Since we cannot make sure the 'reg_size' will always be none zero here, and then if 'reg_size' equals to zero, the kzalloc() will return ZERO_SIZE_PTR, which equals to ((void *)16). So this patch fix this with just doing the 'reg_size' zero check before calling kzalloc(). Signed-off-by: Xiubo Li Signed-off-by: Mark Brown diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index 3fa77d5..8fff5b6 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c @@ -72,6 +72,9 @@ int snd_soc_cache_init(struct snd_soc_codec *codec) reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; + if (!reg_size) + return -EINVAL; + mutex_init(&codec->cache_rw_mutex); dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n", -- cgit v0.10.2 From b5fc40d3b37bdb3524cdf1f550bd0c3b05ac3888 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 2 Jun 2014 16:08:21 +0100 Subject: ASoC: cache: Fix error code when not using ASoC level cache It is not an error to have no cache so we shouldn't return an error code and cause our callers to fail, just silently do nothing instead. Thanks to Jarkko for identify the problematic commit. Reported-by: Jarkko Nikula Reported-by: Fabio Estevam Signed-off-by: Mark Brown diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index 8fff5b6..00e70b6 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c @@ -73,7 +73,7 @@ int snd_soc_cache_init(struct snd_soc_codec *codec) reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; if (!reg_size) - return -EINVAL; + return 0; mutex_init(&codec->cache_rw_mutex); -- cgit v0.10.2