[alsa-devel] [PATCH 02/25] ASoC: soc-component: add snd_soc_component_get/put()
Kuninori Morimoto
kuninori.morimoto.gx at renesas.com
Wed Jul 24 03:51:23 CEST 2019
From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
ALSA SoC is calling try_module_get()/module_put() based on
component->driver->module_get_upon_open.
To keep simple and readable code, we should create its function.
This patch adds new snd_soc_component_get/put().
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
include/sound/soc-component.h | 5 +++++
sound/soc/soc-component.c | 18 ++++++++++++++++++
sound/soc/soc-core.c | 9 ++++-----
sound/soc/soc-pcm.c | 10 ++++------
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index d2f94cf..57270c2 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -279,6 +279,11 @@ void snd_soc_component_init_regmap(struct snd_soc_component *component,
void snd_soc_component_exit_regmap(struct snd_soc_component *component);
#endif
+int snd_soc_component_module_get(struct snd_soc_component *component,
+ int has_flags);
+void snd_soc_component_module_put(struct snd_soc_component *component,
+ int has_flags);
+
static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
void *data)
{
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index e19f78b..cf6dfb9 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -5,6 +5,7 @@
// Copyright (C) 2019 Renesas Electronics Corp.
// Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
//
+#include <linux/module.h>
#include <sound/soc.h>
/**
@@ -267,3 +268,20 @@ int snd_soc_component_set_jack(struct snd_soc_component *component,
return -ENOTSUPP;
}
EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
+
+int snd_soc_component_module_get(struct snd_soc_component *component,
+ int has_flags)
+{
+ if (component->driver->module_get_upon_open == !!has_flags &&
+ !try_module_get(component->dev->driver->owner))
+ return -ENODEV;
+
+ return 0;
+}
+
+void snd_soc_component_module_put(struct snd_soc_component *component,
+ int has_flags)
+{
+ if (component->driver->module_get_upon_open == !!has_flags)
+ module_put(component->dev->driver->owner);
+}
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index b67e72f..83b04d9 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -967,8 +967,7 @@ static void soc_cleanup_component(struct snd_soc_component *component)
snd_soc_dapm_free(snd_soc_component_get_dapm(component));
soc_cleanup_component_debugfs(component);
component->card = NULL;
- if (!component->driver->module_get_upon_open)
- module_put(component->dev->driver->owner);
+ snd_soc_component_module_put(component, 0);
}
static void soc_remove_component(struct snd_soc_component *component)
@@ -1296,9 +1295,9 @@ static int soc_probe_component(struct snd_soc_card *card,
return 0;
}
- if (!component->driver->module_get_upon_open &&
- !try_module_get(component->dev->driver->owner))
- return -ENODEV;
+ ret = snd_soc_component_module_get(component, 0);
+ if (ret < 0)
+ return ret;
component->card = card;
dapm->card = card;
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index fabeac1..5a59319 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -15,7 +15,6 @@
#include <linux/delay.h>
#include <linux/pinctrl/consumer.h>
#include <linux/pm_runtime.h>
-#include <linux/module.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/export.h>
@@ -440,12 +439,12 @@ static int soc_pcm_components_open(struct snd_pcm_substream *substream,
component = rtdcom->component;
*last = component;
- if (component->driver->module_get_upon_open &&
- !try_module_get(component->dev->driver->owner)) {
+ ret = snd_soc_component_module_get(component, 1);
+ if (ret < 0) {
dev_err(component->dev,
"ASoC: can't get module %s\n",
component->name);
- return -ENODEV;
+ return ret;
}
if (!component->driver->ops ||
@@ -481,8 +480,7 @@ static int soc_pcm_components_close(struct snd_pcm_substream *substream,
component->driver->ops->close)
component->driver->ops->close(substream);
- if (component->driver->module_get_upon_open)
- module_put(component->dev->driver->owner);
+ snd_soc_component_module_put(component, 1);
}
return 0;
--
2.7.4
More information about the Alsa-devel
mailing list