From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
"Bard Liao" <yung-chuan.liao@linux.intel.com>,
Jaroslav Kysela <perex@perex.cz>,
"Kai Vehmanen" <kai.vehmanen@linux.intel.com>,
Kiseok Jo <kiseok.jo@irondevice.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
"Peter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
Takashi Iwai <tiwai@suse.com>,
"Vijendar Mukunda" <Vijendar.Mukunda@amd.com>,
Benjamin Bara <benjamin.bara@skidata.com>,
<linux-sound@vger.kernel.org>
Subject: Re: [PATCH 1/7] ASoC: soc-component: use dapm->component instead of container_of()
Date: Wed, 9 Apr 2025 09:59:50 +0200 [thread overview]
Message-ID: <921a38aa-8a75-4561-b505-14961d9e20b5@intel.com> (raw)
In-Reply-To: <87o6x69h4y.wl-kuninori.morimoto.gx@renesas.com>
On 2025-04-09 4:57 AM, Kuninori Morimoto wrote:
> 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);
> }
>
> Because (a) uses container_of(), dapm of component works, but
> dapm of others will be "unknown" pointer (= not NULL).
>
> OTOH, we will call snd_soc_dapm_init() (X) to initialize dapm, and
> it will be called from snd_soc_bind_card() (p) or
> soc_probe_component() (q) with pointer (component/NULL).
>
> (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 others (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>
> Cc: Benjamin Bara <benjamin.bara@skidata.com>
> ---
> include/sound/soc-component.h | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
> index 61534ac0edd1..63928773df32 100644
> --- a/include/sound/soc-component.h
> +++ b/include/sound/soc-component.h
> @@ -265,15 +265,11 @@ struct snd_soc_component {
> * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
> * embedded in
> * @dapm: The DAPM context to cast to the component
> - *
> - * This function must only be used on DAPM contexts that are known to be part of
> - * a component (e.g. in a component driver). Otherwise the behavior is
> - * undefined.
> */
> static inline struct snd_soc_component *snd_soc_dapm_to_component(
> struct snd_soc_dapm_context *dapm)
> {
> - return container_of(dapm, struct snd_soc_component, dapm);
> + return dapm->component;
> }
>
> /**
Why not drop the wrapper all along? Personally, I find assignment 'comp
= dapm->component' more readable than the wrapper above. We have very
long prefixes in sound/soc/ in general, and the devs end up reaching
char line-limits.
I'd rather focus on 'struct snd_soc_dapm_context' exclusively. A valid
pointer to this type is required for many functions found in
include/sound/ yet the struct is more of framework-internal entity.
Strict separation between dapm-context "for the framework" from
dapm-context "for the user" would grant better readability benefits.
Kind regards,
Czarek
next prev parent reply other threads:[~2025-04-09 8:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 2:56 [PATCH 0/7] ASoC: use snd_soc_dapm_to_component() Kuninori Morimoto
2025-04-09 2:57 ` [PATCH 1/7] ASoC: soc-component: use dapm->component instead of container_of() Kuninori Morimoto
2025-04-09 7:59 ` Cezary Rojewski [this message]
2025-04-10 0:19 ` Kuninori Morimoto
2025-04-11 2:04 ` Kuninori Morimoto
2025-04-11 9:07 ` Cezary Rojewski
2025-04-13 23:39 ` Kuninori Morimoto
2025-04-14 2:01 ` Kuninori Morimoto
2025-04-17 9:34 ` Cezary Rojewski
2025-04-17 23:00 ` Kuninori Morimoto
2025-04-09 2:57 ` [PATCH 2/7] ASoC: amd: use snd_soc_dapm_to_component() Kuninori Morimoto
2025-04-09 2:57 ` [PATCH 3/7] ASoC: sma1307: " Kuninori Morimoto
2025-04-09 2:57 ` [PATCH 4/7] ASoC: intel: " Kuninori Morimoto
2025-04-09 8:03 ` Cezary Rojewski
2025-04-10 0:20 ` Kuninori Morimoto
2025-04-09 2:57 ` [PATCH 5/7] ASoC: mediatek: " Kuninori Morimoto
2025-04-09 2:57 ` [PATCH 6/7] ASoC: soc-dapm: " Kuninori Morimoto
2025-04-09 2:57 ` [PATCH 7/7] ASoC: soc-topology: " Kuninori Morimoto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=921a38aa-8a75-4561-b505-14961d9e20b5@intel.com \
--to=cezary.rojewski@intel.com \
--cc=Vijendar.Mukunda@amd.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=benjamin.bara@skidata.com \
--cc=broonie@kernel.org \
--cc=kai.vehmanen@linux.intel.com \
--cc=kiseok.jo@irondevice.com \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=ranjani.sridharan@linux.intel.com \
--cc=tiwai@suse.com \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox