ASoC: Intel: Skylake: mem leak in skl register function
authorKamil Duljas <kamil.duljas@gmail.com>
Thu, 16 Nov 2023 22:41:13 +0000 (23:41 +0100)
committerMark Brown <broonie@kernel.org>
Fri, 17 Nov 2023 12:47:51 +0000 (12:47 +0000)
skl_platform_register() uses krealloc. When krealloc is fail,
then previous memory is not freed. The leak is also when soc
component registration failed.

Signed-off-by: Kamil Duljas <kamil.duljas@gmail.com>
Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Link: https://lore.kernel.org/r/20231116224112.2209-2-kamil.duljas@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/skylake/skl-pcm.c

index 18866bc415a55a83faa1fb05f32e3be831afb2f9..174aae6e0398f2c311f2e53121681fe74e1bd6be 100644 (file)
@@ -1464,6 +1464,7 @@ int skl_platform_register(struct device *dev)
                dais = krealloc(skl->dais, sizeof(skl_fe_dai) +
                                sizeof(skl_platform_dai), GFP_KERNEL);
                if (!dais) {
+                       kfree(skl->dais);
                        ret = -ENOMEM;
                        goto err;
                }
@@ -1476,8 +1477,10 @@ int skl_platform_register(struct device *dev)
 
        ret = devm_snd_soc_register_component(dev, &skl_component,
                                         skl->dais, num_dais);
-       if (ret)
+       if (ret) {
+               kfree(skl->dais);
                dev_err(dev, "soc component registration failed %d\n", ret);
+       }
 err:
        return ret;
 }