Commit cd46f382 authored by Peter Ujfalusi's avatar Peter Ujfalusi Committed by Mark Brown

ASoC: compress/component: Use module_get_when_open/put_when_close for cstream

Currently the try_module_get() and module_put() is not possible for
compressed streams if the module_get_upon_open is set to 1 which means that\
the components are not protected in a same way as components when normal
audio is used.

SOF is setting module_get_upon_open to 1 for component drivers which works
correctly for audio stream but when compressed stream is used then the
module is not protected.

Convert the compress open and free operation to mimic the steps of it's
pcm counterpart to fix this issue.
Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20210901095255.3617-3-peter.ujfalusi@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent a739fdc2
...@@ -453,8 +453,10 @@ int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, ...@@ -453,8 +453,10 @@ int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
const struct of_phandle_args *args, const struct of_phandle_args *args,
const char **dai_name); const char **dai_name);
int snd_soc_component_compr_open(struct snd_compr_stream *cstream); int snd_soc_component_compr_open(struct snd_soc_component *component,
void snd_soc_component_compr_free(struct snd_compr_stream *cstream, struct snd_compr_stream *cstream);
void snd_soc_component_compr_free(struct snd_soc_component *component,
struct snd_compr_stream *cstream,
int rollback); int rollback);
int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd); int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
......
...@@ -423,43 +423,36 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); ...@@ -423,43 +423,36 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
#endif #endif
int snd_soc_component_compr_open(struct snd_compr_stream *cstream) int snd_soc_component_compr_open(struct snd_soc_component *component,
struct snd_compr_stream *cstream)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; int ret = 0;
struct snd_soc_component *component;
int i, ret;
for_each_rtd_components(rtd, i, component) { if (component->driver->compress_ops &&
if (component->driver->compress_ops && component->driver->compress_ops->open)
component->driver->compress_ops->open) { ret = component->driver->compress_ops->open(component, cstream);
ret = component->driver->compress_ops->open(component, cstream);
if (ret < 0) /* mark substream if succeeded */
return soc_component_ret(component, ret); if (ret == 0)
}
soc_component_mark_push(component, cstream, compr_open); soc_component_mark_push(component, cstream, compr_open);
}
return 0; return soc_component_ret(component, ret);
} }
EXPORT_SYMBOL_GPL(snd_soc_component_compr_open); EXPORT_SYMBOL_GPL(snd_soc_component_compr_open);
void snd_soc_component_compr_free(struct snd_compr_stream *cstream, void snd_soc_component_compr_free(struct snd_soc_component *component,
struct snd_compr_stream *cstream,
int rollback) int rollback)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; if (rollback && !soc_component_mark_match(component, cstream, compr_open))
struct snd_soc_component *component; return;
int i;
for_each_rtd_components(rtd, i, component) {
if (rollback && !soc_component_mark_match(component, cstream, compr_open))
continue;
if (component->driver->compress_ops && if (component->driver->compress_ops &&
component->driver->compress_ops->free) component->driver->compress_ops->free)
component->driver->compress_ops->free(component, cstream); component->driver->compress_ops->free(component, cstream);
soc_component_mark_pop(component, cstream, compr_open); /* remove marked substream */
} soc_component_mark_pop(component, cstream, compr_open);
} }
EXPORT_SYMBOL_GPL(snd_soc_component_compr_free); EXPORT_SYMBOL_GPL(snd_soc_component_compr_free);
......
...@@ -22,6 +22,39 @@ ...@@ -22,6 +22,39 @@
#include <sound/soc-link.h> #include <sound/soc-link.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
static int snd_soc_compr_components_open(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
int ret = 0;
int i;
for_each_rtd_components(rtd, i, component) {
ret = snd_soc_component_module_get_when_open(component, cstream);
if (ret < 0)
break;
ret = snd_soc_component_compr_open(component, cstream);
if (ret < 0)
break;
}
return ret;
}
static void snd_soc_compr_components_free(struct snd_compr_stream *cstream,
int rollback)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
int i;
for_each_rtd_components(rtd, i, component) {
snd_soc_component_compr_free(component, cstream, rollback);
snd_soc_component_module_put_when_close(component, cstream, rollback);
}
}
static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback) static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_pcm_runtime *rtd = cstream->private_data;
...@@ -44,7 +77,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback) ...@@ -44,7 +77,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
snd_soc_link_compr_shutdown(cstream, rollback); snd_soc_link_compr_shutdown(cstream, rollback);
snd_soc_component_compr_free(cstream, rollback); snd_soc_compr_components_free(cstream, rollback);
snd_soc_dai_compr_shutdown(cpu_dai, cstream, rollback); snd_soc_dai_compr_shutdown(cpu_dai, cstream, rollback);
...@@ -80,7 +113,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) ...@@ -80,7 +113,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
if (ret < 0) if (ret < 0)
goto err; goto err;
ret = snd_soc_component_compr_open(cstream); ret = snd_soc_compr_components_open(cstream);
if (ret < 0) if (ret < 0)
goto err; goto err;
...@@ -137,7 +170,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) ...@@ -137,7 +170,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = snd_soc_component_compr_open(cstream); ret = snd_soc_compr_components_open(cstream);
if (ret < 0) if (ret < 0)
goto open_err; goto open_err;
...@@ -160,7 +193,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) ...@@ -160,7 +193,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
return 0; return 0;
machine_err: machine_err:
snd_soc_component_compr_free(cstream, 1); snd_soc_compr_components_free(cstream, 1);
open_err: open_err:
snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1); snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
out: out:
...@@ -205,7 +238,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) ...@@ -205,7 +238,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
snd_soc_link_compr_shutdown(cstream, 0); snd_soc_link_compr_shutdown(cstream, 0);
snd_soc_component_compr_free(cstream, 0); snd_soc_compr_components_free(cstream, 0);
snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment