Skip to content

Commit 96e311b

Browse files
morimotobroonie
authored andcommitted
ASoC: soc-dapm: use dapm->component instead of container_of()
Because struct snd_soc_dapm_context is soc-dapm framework specific, user driver don't need to access its member directly, we would like to hide them. struct snd_soc_dapm_context will be removed from header in the future. Now, snd_soc_dapm_to_component() (A) will convert dapm to component by container_of() (a). (A) static inline struct snd_soc_component *snd_soc_dapm_to_component( struct snd_soc_dapm_context *dapm) { (a) return container_of(dapm, struct snd_soc_component, dapm); } dapm of component works, but dapm of card will be "unknown" pointer (= not NULL), because (a) is using "container_of()". OTOH, ASoC will call snd_soc_dapm_init() (X) to initialize dapm, and it will be called from snd_soc_bind_card() (p) (for card) or soc_probe_component() (q) (for component) with component pointer. (p) static int snd_soc_bind_card(...) { ... (X) snd_soc_dapm_init(..., NULL); ... ^^^^ } (q) static int soc_probe_component(...) { ... (X) snd_soc_dapm_init(..., component); ... ^^^^^^^^^ } And snd_soc_dapm_init() (X) will fill dapm->component (x) (X) void snd_soc_dapm_init(..., component, ...) { ... (x) dapm->component = component; ... } We can simply use dapm->component in snd_soc_dapm_to_component() (A). In this case, dapm of card (p) will be just NULL. Use dapm->component instead of container_of(). The picky note can be removed by this patch. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://patch.msgid.link/87a53ax06q.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c8df096 commit 96e311b

3 files changed

Lines changed: 7 additions & 15 deletions

File tree

include/sound/soc-component.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,6 @@ struct snd_soc_component {
260260
#define for_each_component_dais_safe(component, dai, _dai)\
261261
list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
262262

263-
/**
264-
* snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
265-
* embedded in
266-
* @dapm: The DAPM context to cast to the component
267-
*
268-
* This function must only be used on DAPM contexts that are known to be part of
269-
* a component (e.g. in a component driver). Otherwise the behavior is
270-
* undefined.
271-
*/
272-
static inline struct snd_soc_component *snd_soc_dapm_to_component(
273-
struct snd_soc_dapm_context *dapm)
274-
{
275-
return container_of(dapm, struct snd_soc_component, dapm);
276-
}
277-
278263
/**
279264
* snd_soc_component_get_dapm() - Returns the DAPM context associated with a
280265
* component

include/sound/soc-dapm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
662662
int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s);
663663
struct device *snd_soc_dapm_to_dev(struct snd_soc_dapm_context *dapm);
664664
struct snd_soc_card *snd_soc_dapm_to_card(struct snd_soc_dapm_context *dapm);
665+
struct snd_soc_component *snd_soc_dapm_to_component(struct snd_soc_dapm_context *dapm);
665666

666667
/* dapm path setup */
667668
int snd_soc_dapm_new_widgets(struct snd_soc_card *card);

sound/soc/soc-dapm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ struct snd_soc_card *snd_soc_dapm_to_card(struct snd_soc_dapm_context *dapm)
180180
}
181181
EXPORT_SYMBOL_GPL(snd_soc_dapm_to_card);
182182

183+
struct snd_soc_component *snd_soc_dapm_to_component(struct snd_soc_dapm_context *dapm)
184+
{
185+
return dapm->component;
186+
}
187+
EXPORT_SYMBOL_GPL(snd_soc_dapm_to_component);
188+
183189
static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
184190
{
185191
return !list_empty(&w->dirty);

0 commit comments

Comments
 (0)