ASoC: cache: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
[firefly-linux-kernel-4.4.55.git] / sound / soc / soc-cache.c
index bfed3e4c45ffa708910e580bf02359a7b6b3c509..8fff5b6d86dbf12844367414caec1cb443942919 100644 (file)
@@ -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",
@@ -162,8 +165,6 @@ static int snd_soc_flat_cache_sync(struct snd_soc_codec *codec)
                                                  i, codec_drv->reg_word_size) == val)
                                continue;
 
-               WARN_ON(!snd_soc_codec_writable_register(codec, i));
-
                ret = snd_soc_write(codec, i, val);
                if (ret)
                        return ret;