ASoC: codecs: rt*-sdw: fix memory leak in set_sdw_stream()
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Fri, 15 May 2020 21:15:30 +0000 (16:15 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 18 May 2020 11:38:29 +0000 (12:38 +0100)
Now that the sdw_stream is allocated in machine driver,
set_sdw_stream() is also called with a NULL argument during the
dailink shutdown.

In this case, the drivers should not allocate any memory, and just
return.

Detected with KASAN/kmemleak.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Cc: Oder Chiou <oder_chiou@realtek.com>
Cc: Shuming Fan <shumingf@realtek.com>
Cc: Jack Yu <jack.yu@realtek.com>
Link: https://lore.kernel.org/r/20200515211531.11416-3-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/rt1308-sdw.c
sound/soc/codecs/rt5682.c
sound/soc/codecs/rt700.c
sound/soc/codecs/rt711.c
sound/soc/codecs/rt715.c

index 4b88fa8..91cc5a1 100644 (file)
@@ -482,6 +482,9 @@ static int rt1308_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
        struct sdw_stream_data *stream;
 
+       if (!sdw_stream)
+               return 0;
+
        stream = kzalloc(sizeof(*stream), GFP_KERNEL);
        if (!stream)
                return -ENOMEM;
index 5d3b117..046e611 100644 (file)
@@ -2935,6 +2935,9 @@ static int rt5682_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
        struct sdw_stream_data *stream;
 
+       if (!sdw_stream)
+               return 0;
+
        stream = kzalloc(sizeof(*stream), GFP_KERNEL);
        if (!stream)
                return -ENOMEM;
index ff68f0e..687ac21 100644 (file)
@@ -860,6 +860,9 @@ static int rt700_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
        struct sdw_stream_data *stream;
 
+       if (!sdw_stream)
+               return 0;
+
        stream = kzalloc(sizeof(*stream), GFP_KERNEL);
        if (!stream)
                return -ENOMEM;
index 2daed76..65b59db 100644 (file)
@@ -906,6 +906,9 @@ static int rt711_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 {
        struct sdw_stream_data *stream;
 
+       if (!sdw_stream)
+               return 0;
+
        stream = kzalloc(sizeof(*stream), GFP_KERNEL);
        if (!stream)
                return -ENOMEM;
index 2cbc57b..099c8bd 100644 (file)
@@ -530,6 +530,9 @@ static int rt715_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
 
        struct sdw_stream_data *stream;
 
+       if (!sdw_stream)
+               return 0;
+
        stream = kzalloc(sizeof(*stream), GFP_KERNEL);
        if (!stream)
                return -ENOMEM;