ASoC: Intel: check and clear runtime module pointer
authorJie Yang <yang.jie@intel.com>
Sat, 30 May 2015 14:33:58 +0000 (22:33 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 2 Jun 2015 14:34:11 +0000 (15:34 +0100)
Add check runtime module pointers before freeing them, and clear
them to NULL after freed.

With this implemented, we can avoid NULL pointer dereference or
double free errors.

Signed-off-by: Jie Yang <yang.jie@intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/haswell/sst-haswell-pcm.c

index 23ae0400d6db99668b3d2b48b47eb003d2fc2e46..f97fa5ab93d3676112bbf871a4ae85c9a01797ca 100644 (file)
@@ -928,10 +928,15 @@ static void hsw_pcm_free_modules(struct hsw_priv_data *pdata)
 
        for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
                pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream];
-               sst_hsw_runtime_module_free(pcm_data->runtime);
+               if (pcm_data->runtime){
+                       sst_hsw_runtime_module_free(pcm_data->runtime);
+                       pcm_data->runtime = NULL;
+               }
        }
-       if (sst_hsw_is_module_loaded(hsw, SST_HSW_MODULE_WAVES)) {
+       if (sst_hsw_is_module_loaded(hsw, SST_HSW_MODULE_WAVES) &&
+                               pdata->runtime_waves) {
                sst_hsw_runtime_module_free(pdata->runtime_waves);
+               pdata->runtime_waves = NULL;
        }
 }