ASoC: simple-card-utils: test memory allocation

li->conf will be 0 if it was not DPCM case.
Then, 1) we shouldn't call devm_kcalloc() with size 0,
2) we need NULL pointer check if li->conf was not 0.
This patch fixed above issues.
Special thanks to Pierre-Louis Bossart

Reported-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2019-03-20 13:57:02 +09:00 коммит произвёл Mark Brown
Родитель 16123412a6
Коммит 008fe4e538
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 24D68B725D5487D0
1 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -495,16 +495,21 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
struct snd_soc_dai_link *dai_link; struct snd_soc_dai_link *dai_link;
struct simple_dai_props *dai_props; struct simple_dai_props *dai_props;
struct asoc_simple_dai *dais; struct asoc_simple_dai *dais;
struct snd_soc_codec_conf *cconf; struct snd_soc_codec_conf *cconf = NULL;
int i; int i;
dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL); dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL);
dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL); dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL);
dais = devm_kcalloc(dev, li->dais, sizeof(*dais), GFP_KERNEL); dais = devm_kcalloc(dev, li->dais, sizeof(*dais), GFP_KERNEL);
cconf = devm_kcalloc(dev, li->conf, sizeof(*cconf), GFP_KERNEL);
if (!dai_props || !dai_link || !dais) if (!dai_props || !dai_link || !dais)
return -ENOMEM; return -ENOMEM;
if (li->conf) {
cconf = devm_kcalloc(dev, li->conf, sizeof(*cconf), GFP_KERNEL);
if (!cconf)
return -ENOMEM;
}
/* /*
* Use snd_soc_dai_link_component instead of legacy style * Use snd_soc_dai_link_component instead of legacy style
* It is codec only. but cpu/platform will be supported in the future. * It is codec only. but cpu/platform will be supported in the future.