Unverified Commit 0d8902d5 authored by Mark Brown's avatar Mark Brown
Browse files

Merge series "ASoC: merge soc_pcm_hw_param() rollback and soc_pcm_hw_free()"...

Merge series "ASoC: merge soc_pcm_hw_param() rollback and soc_pcm_hw_free()" from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

Hi Mark

soc_pcm_hw_params() does rollback when failed (A),
but, it is almost same as soc_pcm_hw_free().

	static int soc_pcm_hw_params(xxx)
	{
		...
		if (ret < 0)
			goto xxx_err;
		...
		return ret;

 ^	component_err:
 |		...
 |	interface_err:
(A)		...
 |	codec_err:
 |		...
 v		return ret;
	}

This kind of duplicated code can be a hotbed of bugs,
thus, this patch-set share soc_pcm_hw_free() and rollback.

Kuninori Morimoto (6):
  ASoC: soc.h: remove for_each_rtd_dais_rollback()
  ASoC: soc-pcm: move soc_pcm_hw_free() next to soc_pcm_hw_params()
  ASoC: soc-link: add mark for snd_soc_link_hw_params/free()
  ASoC: soc-component: add mark for snd_soc_pcm_component_hw_params/free()
  ASoC: soc-dai: add mark for snd_soc_dai_hw_params/free()
  ASoC: soc-pcm: add soc_pcm_hw_clean() and call it from soc_pcm_hw_params/free()

 include/sound/soc-component.h |   6 +-
 include/sound/soc-dai.h       |   4 +-
 include/sound/soc-link.h      |   3 +-
 include/sound/soc.h           |   7 +-
 sound/soc/soc-component.c     |  19 ++---
 sound/soc/soc-dai.c           |  13 +++-
 sound/soc/soc-dapm.c          |   4 +-
 sound/soc/soc-link.c          |  12 +++-
 sound/soc/soc-pcm.c           | 131 ++++++++++++++--------------------
 9 files changed, 97 insertions(+), 102 deletions(-)

--
2.25.1
parents 155eacf8 4662c596
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -220,6 +220,7 @@ struct snd_soc_component {
	/* function mark */
	struct snd_pcm_substream *mark_module;
	struct snd_pcm_substream *mark_open;
	struct snd_pcm_substream *mark_hw_params;
	void *mark_pm;

#ifdef CONFIG_DEBUG_FS
@@ -459,10 +460,9 @@ int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
				    struct snd_pcm_hw_params *params,
				    struct snd_soc_component **last);
				    struct snd_pcm_hw_params *params);
void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
				   struct snd_soc_component *last);
				   int rollback);
int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
				  int cmd);
int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
+3 −1
Original line number Diff line number Diff line
@@ -149,7 +149,8 @@ int snd_soc_dai_hw_params(struct snd_soc_dai *dai,
			  struct snd_pcm_substream *substream,
			  struct snd_pcm_hw_params *params);
void snd_soc_dai_hw_free(struct snd_soc_dai *dai,
			 struct snd_pcm_substream *substream);
			 struct snd_pcm_substream *substream,
			 int rollback);
int snd_soc_dai_startup(struct snd_soc_dai *dai,
			struct snd_pcm_substream *substream);
void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
@@ -390,6 +391,7 @@ struct snd_soc_dai {

	/* function mark */
	struct snd_pcm_substream *mark_startup;
	struct snd_pcm_substream *mark_hw_params;

	/* bit field */
	unsigned int probed:1;
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ void snd_soc_link_shutdown(struct snd_pcm_substream *substream,
int snd_soc_link_prepare(struct snd_pcm_substream *substream);
int snd_soc_link_hw_params(struct snd_pcm_substream *substream,
			   struct snd_pcm_hw_params *params);
void snd_soc_link_hw_free(struct snd_pcm_substream *substream);
void snd_soc_link_hw_free(struct snd_pcm_substream *substream,
			  int rollback);
int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd);

int snd_soc_link_compr_startup(struct snd_compr_stream *cstream);
+1 −6
Original line number Diff line number Diff line
@@ -1161,6 +1161,7 @@ struct snd_soc_pcm_runtime {

	/* function mark */
	struct snd_pcm_substream *mark_startup;
	struct snd_pcm_substream *mark_hw_params;

	/* bit field */
	unsigned int pop_wait:1;
@@ -1183,21 +1184,15 @@ struct snd_soc_pcm_runtime {
	for ((i) = 0;							\
	     ((i) < rtd->num_cpus) && ((dai) = asoc_rtd_to_cpu(rtd, i)); \
	     (i)++)
#define for_each_rtd_cpu_dais_rollback(rtd, i, dai)		\
	for (; (--(i) >= 0) && ((dai) = asoc_rtd_to_cpu(rtd, i));)
#define for_each_rtd_codec_dais(rtd, i, dai)				\
	for ((i) = 0;							\
	     ((i) < rtd->num_codecs) && ((dai) = asoc_rtd_to_codec(rtd, i)); \
	     (i)++)
#define for_each_rtd_codec_dais_rollback(rtd, i, dai)		\
	for (; (--(i) >= 0) && ((dai) = asoc_rtd_to_codec(rtd, i));)
#define for_each_rtd_dais(rtd, i, dai)					\
	for ((i) = 0;							\
	     ((i) < (rtd)->num_cpus + (rtd)->num_codecs) &&		\
		     ((dai) = (rtd)->dais[i]);				\
	     (i)++)
#define for_each_rtd_dais_rollback(rtd, i, dai)		\
	for (; (--(i) >= 0) && ((dai) = (rtd)->dais[i]);)

void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);

+10 −9
Original line number Diff line number Diff line
@@ -779,8 +779,7 @@ int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream)
}

int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
				    struct snd_pcm_hw_params *params,
				    struct snd_soc_component **last)
				    struct snd_pcm_hw_params *params)
{
	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
	struct snd_soc_component *component;
@@ -790,33 +789,35 @@ int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
		if (component->driver->hw_params) {
			ret = component->driver->hw_params(component,
							   substream, params);
			if (ret < 0) {
				*last = component;
			if (ret < 0)
				return soc_component_ret(component, ret);
		}
		}
		/* mark substream if succeeded */
		soc_component_mark_push(component, substream, hw_params);
	}

	*last = NULL;
	return 0;
}

void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
				   struct snd_soc_component *last)
				   int rollback)
{
	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
	struct snd_soc_component *component;
	int i, ret;

	for_each_rtd_components(rtd, i, component) {
		if (component == last)
			break;
		if (rollback && !soc_component_mark_match(component, substream, hw_params))
			continue;

		if (component->driver->hw_free) {
			ret = component->driver->hw_free(component, substream);
			if (ret < 0)
				soc_component_ret(component, ret);
		}

		/* remove marked substream */
		soc_component_mark_pop(component, substream, hw_params);
	}
}

Loading