diff options
author | Xiubo Li <Li.Xiubo@freescale.com> | 2014-02-27 21:48:19 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-03-03 23:32:19 -0500 |
commit | 931f27c6e892fdfe98896055e0df7962e21969d9 (patch) | |
tree | 0c655c9d5a9f7966560b53ce78427affff51071e /sound/soc/soc-cache.c | |
parent | 939d9f16994166156fa3d6dfece9c46b92e368e0 (diff) |
ASoC: cache: Do the codec->reg_cache zero pionter check
For the snd_soc_cache_init(), the reg_size maybe zero and then the value
of codec->reg_cache, which is alloced via kzalloc, maybe equal to
ZERO_SIZE_PTR. If the reg parameter of snd_soc_cache_write() is large enough,
the cache[idx] = val maybe cause the kernel crash...
So this patch fix this via doing the zero pionter check of it.
Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/soc-cache.c')
-rw-r--r-- | sound/soc/soc-cache.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index 375dc6dfba4e..bfed3e4c45ff 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c | |||
@@ -96,8 +96,7 @@ int snd_soc_cache_exit(struct snd_soc_codec *codec) | |||
96 | { | 96 | { |
97 | dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n", | 97 | dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n", |
98 | codec->name); | 98 | codec->name); |
99 | if (!codec->reg_cache) | 99 | |
100 | return 0; | ||
101 | kfree(codec->reg_cache); | 100 | kfree(codec->reg_cache); |
102 | codec->reg_cache = NULL; | 101 | codec->reg_cache = NULL; |
103 | return 0; | 102 | return 0; |
@@ -117,8 +116,9 @@ int snd_soc_cache_read(struct snd_soc_codec *codec, | |||
117 | return -EINVAL; | 116 | return -EINVAL; |
118 | 117 | ||
119 | mutex_lock(&codec->cache_rw_mutex); | 118 | mutex_lock(&codec->cache_rw_mutex); |
120 | *value = snd_soc_get_cache_val(codec->reg_cache, reg, | 119 | if (!ZERO_OR_NULL_PTR(codec->reg_cache)) |
121 | codec->driver->reg_word_size); | 120 | *value = snd_soc_get_cache_val(codec->reg_cache, reg, |
121 | codec->driver->reg_word_size); | ||
122 | mutex_unlock(&codec->cache_rw_mutex); | 122 | mutex_unlock(&codec->cache_rw_mutex); |
123 | 123 | ||
124 | return 0; | 124 | return 0; |
@@ -136,8 +136,9 @@ int snd_soc_cache_write(struct snd_soc_codec *codec, | |||
136 | unsigned int reg, unsigned int value) | 136 | unsigned int reg, unsigned int value) |
137 | { | 137 | { |
138 | mutex_lock(&codec->cache_rw_mutex); | 138 | mutex_lock(&codec->cache_rw_mutex); |
139 | snd_soc_set_cache_val(codec->reg_cache, reg, value, | 139 | if (!ZERO_OR_NULL_PTR(codec->reg_cache)) |
140 | codec->driver->reg_word_size); | 140 | snd_soc_set_cache_val(codec->reg_cache, reg, value, |
141 | codec->driver->reg_word_size); | ||
141 | mutex_unlock(&codec->cache_rw_mutex); | 142 | mutex_unlock(&codec->cache_rw_mutex); |
142 | 143 | ||
143 | return 0; | 144 | return 0; |