From 4a81e8f30d0b422b7f10562952124d719f73b071 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 26 Jul 2019 13:49:54 +0900 Subject: ASoC: soc-component: add snd_soc_component_get/put() 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 Link: https://lore.kernel.org/r/87h8795ro4.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-component.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'sound/soc/soc-component.c') diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index e19f78bfb919..ac2d7bd5d844 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 // +#include #include /** @@ -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 upon_open) +{ + if (component->driver->module_get_upon_open == !!upon_open && + !try_module_get(component->dev->driver->owner)) + return -ENODEV; + + return 0; +} + +void snd_soc_component_module_put(struct snd_soc_component *component, + int upon_open) +{ + if (component->driver->module_get_upon_open == !!upon_open) + module_put(component->dev->driver->owner); +} -- cgit v1.2.3