Skip to content

Commit

Permalink
ASoC: soc-pcm: add for_each_dapm_widgets() macro
Browse files Browse the repository at this point in the history
This patch adds new for_each_dapm_widgets() macro and use it.

Signed-off-by: Kuninori Morimoto <[email protected]>
Reviewed-by: Ranjani Sridharan <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
morimoto authored and broonie committed Feb 11, 2020
1 parent 5c25bd6 commit 09e88f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 5 additions & 0 deletions include/sound/soc-dapm.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@ struct snd_soc_dapm_widget_list {
struct snd_soc_dapm_widget *widgets[0];
};

#define for_each_dapm_widgets(list, i, widget) \
for ((i) = 0; \
(i) < list->num_widgets && (widget = list->widgets[i]); \
(i)++)

struct snd_soc_dapm_stats {
int power_checks;
int path_checks;
Expand Down
8 changes: 2 additions & 6 deletions sound/soc/soc-dapm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1724,9 +1724,7 @@ static void dapm_widget_update(struct snd_soc_card *card)

wlist = dapm_kcontrol_get_wlist(update->kcontrol);

for (wi = 0; wi < wlist->num_widgets; wi++) {
w = wlist->widgets[wi];

for_each_dapm_widgets(wlist, wi, w) {
if (w->event && (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
if (ret != 0)
Expand All @@ -1753,9 +1751,7 @@ static void dapm_widget_update(struct snd_soc_card *card)
w->name, ret);
}

for (wi = 0; wi < wlist->num_widgets; wi++) {
w = wlist->widgets[wi];

for_each_dapm_widgets(wlist, wi, w) {
if (w->event && (w->event_flags & SND_SOC_DAPM_POST_REG)) {
ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
if (ret != 0)
Expand Down
17 changes: 9 additions & 8 deletions sound/soc/soc-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,12 @@ static inline struct snd_soc_dapm_widget *
static int widget_in_list(struct snd_soc_dapm_widget_list *list,
struct snd_soc_dapm_widget *widget)
{
struct snd_soc_dapm_widget *w;
int i;

for (i = 0; i < list->num_widgets; i++) {
if (widget == list->widgets[i])
for_each_dapm_widgets(list, i, w)
if (widget == w)
return 1;
}

return 0;
}
Expand Down Expand Up @@ -1422,12 +1422,13 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
struct snd_soc_card *card = fe->card;
struct snd_soc_dapm_widget_list *list = *list_;
struct snd_soc_pcm_runtime *be;
struct snd_soc_dapm_widget *widget;
int i, new = 0, err;

/* Create any new FE <--> BE connections */
for (i = 0; i < list->num_widgets; i++) {
for_each_dapm_widgets(list, i, widget) {

switch (list->widgets[i]->id) {
switch (widget->id) {
case snd_soc_dapm_dai_in:
if (stream != SNDRV_PCM_STREAM_PLAYBACK)
continue;
Expand All @@ -1441,10 +1442,10 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
}

/* is there a valid BE rtd for this widget */
be = dpcm_get_be(card, list->widgets[i], stream);
be = dpcm_get_be(card, widget, stream);
if (!be) {
dev_err(fe->dev, "ASoC: no BE found for %s\n",
list->widgets[i]->name);
widget->name);
continue;
}

Expand All @@ -1460,7 +1461,7 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
err = dpcm_be_connect(fe, be, stream);
if (err < 0) {
dev_err(fe->dev, "ASoC: can't connect %s\n",
list->widgets[i]->name);
widget->name);
break;
} else if (err == 0) /* already connected */
continue;
Expand Down

0 comments on commit 09e88f8

Please sign in to comment.