From: Kuninori Morimoto Date: Tue, 20 Jan 2026 00:14:54 +0000 (+0000) Subject: ASoC: soc-dapm: add snd_soc_dapm_alloc() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13c84b4c6f218c196c9c72286645247996800427;p=thirdparty%2Fkernel%2Flinux.git ASoC: soc-dapm: add snd_soc_dapm_alloc() 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. Current card/component are using dapm_context instance. But it will be moved to soc-dapm.c, and we can use will be only pointer. Makes it to pointer. Signed-off-by: Kuninori Morimoto Link: https://patch.msgid.link/87h5shqgw1.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index e538784746db..2a2b74b24a60 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -237,8 +237,7 @@ struct snd_soc_component { * the driver will be marked as BROKEN when these fields are removed. */ - /* Don't use these, use snd_soc_component_get_dapm() */ - struct snd_soc_dapm_context dapm; + struct snd_soc_dapm_context *dapm; /* machine specific init */ int (*init)(struct snd_soc_component *component); @@ -268,7 +267,7 @@ struct snd_soc_component { static inline struct snd_soc_dapm_context *snd_soc_component_to_dapm( struct snd_soc_component *component) { - return &component->dapm; + return component->dapm; } /** diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 010d63db5436..6f3e1b57cda3 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -627,6 +627,8 @@ enum snd_soc_dapm_direction { #define SND_SOC_DAPM_EP_SOURCE SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_IN) #define SND_SOC_DAPM_EP_SINK SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_OUT) +struct snd_soc_dapm_context *snd_soc_dapm_alloc(struct device *dev); + int snd_soc_dapm_regulator_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); int snd_soc_dapm_clock_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); int snd_soc_dapm_pinctrl_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); diff --git a/include/sound/soc.h b/include/sound/soc.h index aa0fe6b80293..7d8376c8e1be 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1076,7 +1076,7 @@ struct snd_soc_card { struct list_head dobj_list; /* Generic DAPM context for the card */ - struct snd_soc_dapm_context dapm; + struct snd_soc_dapm_context *dapm; struct snd_soc_dapm_stats dapm_stats; #ifdef CONFIG_DEBUG_FS @@ -1136,7 +1136,7 @@ static inline int snd_soc_card_is_instantiated(struct snd_soc_card *card) static inline struct snd_soc_dapm_context *snd_soc_card_to_dapm(struct snd_soc_card *card) { - return &card->dapm; + return card->dapm; } /* SoC machine DAI configuration, glues a codec and cpu DAI together */ diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index e4b21bf39e59..355ccc95f28b 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2556,6 +2556,10 @@ int snd_soc_register_card(struct snd_soc_card *card) if (!card->name || !card->dev) return -EINVAL; + card->dapm = snd_soc_dapm_alloc(card->dev); + if (!card->dapm) + return -ENOMEM; + dev_set_drvdata(card->dev, card); INIT_LIST_HEAD(&card->widgets); @@ -2840,6 +2844,10 @@ int snd_soc_component_initialize(struct snd_soc_component *component, const struct snd_soc_component_driver *driver, struct device *dev) { + component->dapm = snd_soc_dapm_alloc(dev); + if (!component->dapm) + return -ENOMEM; + INIT_LIST_HEAD(&component->dai_list); INIT_LIST_HEAD(&component->dobj_list); INIT_LIST_HEAD(&component->card_list); diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 4c2007c61ca1..7aef57dcb2a7 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -165,6 +165,11 @@ static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) kfree(buf); } +struct snd_soc_dapm_context *snd_soc_dapm_alloc(struct device *dev) +{ + return devm_kzalloc(dev, sizeof(struct snd_soc_dapm_context), GFP_KERNEL); +} + struct device *snd_soc_dapm_to_dev(struct snd_soc_dapm_context *dapm) { if (dapm->component) @@ -1076,7 +1081,7 @@ static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm, if (ret != 0) goto out; - if (dapm != &card->dapm) + if (dapm != card->dapm) ret = snd_soc_dapm_force_bias_level(dapm, level); if (ret != 0)