aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sound/soc.h1
-rw-r--r--sound/soc/soc-cache.c10
-rw-r--r--sound/soc/soc-core.c15
3 files changed, 6 insertions, 20 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 3f7de6f992c0..62f320f56644 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -687,7 +687,6 @@ struct snd_soc_codec {
687 unsigned int (*read)(struct snd_soc_codec *, unsigned int); 687 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
688 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int); 688 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
689 void *reg_cache; 689 void *reg_cache;
690 const void *reg_def_copy;
691 const struct snd_soc_cache_ops *cache_ops; 690 const struct snd_soc_cache_ops *cache_ops;
692 struct mutex cache_rw_mutex; 691 struct mutex cache_rw_mutex;
693 int val_bytes; 692 int val_bytes;
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index eaa898f8d808..a7f83c0c62ce 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -78,8 +78,8 @@ static int snd_soc_flat_cache_sync(struct snd_soc_codec *codec)
78 ret = snd_soc_cache_read(codec, i, &val); 78 ret = snd_soc_cache_read(codec, i, &val);
79 if (ret) 79 if (ret)
80 return ret; 80 return ret;
81 if (codec->reg_def_copy) 81 if (codec_drv->reg_cache_default)
82 if (snd_soc_get_cache_val(codec->reg_def_copy, 82 if (snd_soc_get_cache_val(codec_drv->reg_cache_default,
83 i, codec_drv->reg_word_size) == val) 83 i, codec_drv->reg_word_size) == val)
84 continue; 84 continue;
85 85
@@ -121,8 +121,10 @@ static int snd_soc_flat_cache_exit(struct snd_soc_codec *codec)
121 121
122static int snd_soc_flat_cache_init(struct snd_soc_codec *codec) 122static int snd_soc_flat_cache_init(struct snd_soc_codec *codec)
123{ 123{
124 if (codec->reg_def_copy) 124 const struct snd_soc_codec_driver *codec_drv = codec->driver;
125 codec->reg_cache = kmemdup(codec->reg_def_copy, 125
126 if (codec_drv->reg_cache_default)
127 codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
126 codec->reg_size, GFP_KERNEL); 128 codec->reg_size, GFP_KERNEL);
127 else 129 else
128 codec->reg_cache = kzalloc(codec->reg_size, GFP_KERNEL); 130 codec->reg_cache = kzalloc(codec->reg_size, GFP_KERNEL);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4ce02e6777e5..bbe833ab657e 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -4201,20 +4201,6 @@ int snd_soc_register_codec(struct device *dev,
4201 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { 4201 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
4202 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 4202 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
4203 codec->reg_size = reg_size; 4203 codec->reg_size = reg_size;
4204 /* it is necessary to make a copy of the default register cache
4205 * because in the case of using a compression type that requires
4206 * the default register cache to be marked as the
4207 * kernel might have freed the array by the time we initialize
4208 * the cache.
4209 */
4210 if (codec_drv->reg_cache_default) {
4211 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
4212 reg_size, GFP_KERNEL);
4213 if (!codec->reg_def_copy) {
4214 ret = -ENOMEM;
4215 goto fail_codec_name;
4216 }
4217 }
4218 } 4204 }
4219 4205
4220 for (i = 0; i < num_dai; i++) { 4206 for (i = 0; i < num_dai; i++) {
@@ -4273,7 +4259,6 @@ found:
4273 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name); 4259 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name);
4274 4260
4275 snd_soc_cache_exit(codec); 4261 snd_soc_cache_exit(codec);
4276 kfree(codec->reg_def_copy);
4277 kfree(codec->name); 4262 kfree(codec->name);
4278 kfree(codec); 4263 kfree(codec);
4279} 4264}