Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: soc-dai: don't use dev_{set/get}_drvdata() on DAI
@ 2026-03-05  1:56 Kuninori Morimoto
  2026-03-05 13:14 ` Charles Keepax
  0 siblings, 1 reply; 6+ messages in thread
From: Kuninori Morimoto @ 2026-03-05  1:56 UTC (permalink / raw)
  To: Bard Liao, Charles Keepax, Jaroslav Kysela, Liam Girdwood,
	Maciej Strozek, Mark Brown, Pierre-Louis Bossart, Takashi Iwai,
	linux-sound

We have 2 type of driver data set functions.

(A)	snd_soc_component_set_drvdata()
(B)	snd_soc_dai_set_drvdata()

Both are using dev_set_drvdata() with own dev

(A)	static inline void snd_soc_component_set_drvdata(...)
	{
		dev_set_drvdata(component->dev, data);
	}			^^^^^^^^^^^^^^

(B)	static inline void snd_soc_dai_set_drvdata(...)
	{
		dev_set_drvdata(dai->dev, data);
	}			^^^^^^^^

But, these are same dev.

	struct snd_soc_dai *snd_soc_register_dai(...)
	{
(A)		struct device *dev = component->dev;
		...
(B)		dai->dev = dev;
		...
	}

This means, if (A) and (B) were called in the same time, private data
will be overwritten.

But, in the same time, commit 5f86d41d0410 ("ASoC: soc-dai: Add private
data to snd_soc_dai") added dai->priv for private data, and sdca_asoc.c
is only user of it.

We can re-use this dai->priv for snd_soc_dai_set_drvdata() (B) instead,
and avoid the issue.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/soc-dai.h    | 4 ++--
 sound/soc/sdca/sdca_asoc.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 224396927aef3..2b006d3de777a 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -536,12 +536,12 @@ static inline unsigned int snd_soc_dai_stream_active(const struct snd_soc_dai *d
 static inline void snd_soc_dai_set_drvdata(struct snd_soc_dai *dai,
 		void *data)
 {
-	dev_set_drvdata(dai->dev, data);
+	dai->priv = data;
 }
 
 static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
 {
-	return dev_get_drvdata(dai->dev);
+	return dai->priv;
 }
 
 /**
diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c
index a342a4e56717a..c53c74952069f 100644
--- a/sound/soc/sdca/sdca_asoc.c
+++ b/sound/soc/sdca/sdca_asoc.c
@@ -1456,7 +1456,7 @@ int sdca_asoc_set_constraints(struct device *dev, struct regmap *regmap,
 		return ret;
 	}
 
-	dai->priv = constraint;
+	snd_soc_dai_set_drvdata(dai, constraint);
 
 	return 0;
 }
@@ -1472,7 +1472,7 @@ EXPORT_SYMBOL_NS(sdca_asoc_set_constraints, "SND_SOC_SDCA");
 void sdca_asoc_free_constraints(struct snd_pcm_substream *substream,
 				struct snd_soc_dai *dai)
 {
-	struct snd_pcm_hw_constraint_list *constraint = dai->priv;
+	struct snd_pcm_hw_constraint_list *constraint = snd_soc_dai_get_drvdata(dai);
 
 	kfree(constraint);
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-09  2:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05  1:56 [PATCH] ASoC: soc-dai: don't use dev_{set/get}_drvdata() on DAI Kuninori Morimoto
2026-03-05 13:14 ` Charles Keepax
2026-03-05 13:34   ` Charles Keepax
2026-03-05 23:59     ` Kuninori Morimoto
2026-03-06 19:44       ` Mark Brown
2026-03-09  2:04         ` Kuninori Morimoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox