ASoC: soc-pcm: fixup try_module_get()/module_put() timing
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Mon, 20 May 2019 01:42:39 +0000 (10:42 +0900)
committerMark Brown <broonie@kernel.org>
Tue, 21 May 2019 20:59:17 +0000 (21:59 +0100)
soc_pcm_components_open/close() try to call
try_module_get()/module_put() based on
component->driver->module_get_upon_open.

Here, the purpose why we need to call these functions are to
checking module reference.
Thus, we need to call try_module_open() even though it doesn't
have .open callback.

The same reason, we need to call module_put() even though it
doesn't have .close

This patch calls try_module_get()/module_put() regardless of
.open/.close

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-pcm.c

index 74c7d38af2c68e26baebb8db113e4393cbee29ab..4a7096a22b28836c818a70f3e5a79a49d8d853db 100644 (file)
@@ -458,10 +458,6 @@ static int soc_pcm_components_open(struct snd_pcm_substream *substream,
                component = rtdcom->component;
                *last = component;
 
-               if (!component->driver->ops ||
-                   !component->driver->ops->open)
-                       continue;
-
                if (component->driver->module_get_upon_open &&
                    !try_module_get(component->dev->driver->owner)) {
                        dev_err(component->dev,
@@ -470,6 +466,10 @@ static int soc_pcm_components_open(struct snd_pcm_substream *substream,
                        return -ENODEV;
                }
 
+               if (!component->driver->ops ||
+                   !component->driver->ops->open)
+                       continue;
+
                ret = component->driver->ops->open(substream);
                if (ret < 0) {
                        dev_err(component->dev,
@@ -495,11 +495,9 @@ static int soc_pcm_components_close(struct snd_pcm_substream *substream,
                if (component == last)
                        break;
 
-               if (!component->driver->ops ||
-                   !component->driver->ops->close)
-                       continue;
-
-               component->driver->ops->close(substream);
+               if (component->driver->ops &&
+                   component->driver->ops->close)
+                       component->driver->ops->close(substream);
 
                if (component->driver->module_get_upon_open)
                        module_put(component->dev->driver->owner);