Skip to content

Commit 9723cab

Browse files
krzkbroonie
authored andcommitted
ASoC: Use inline function for type safety in snd_soc_substream_to_rtd()
A common pattern in sound drivers is getting 'struct snd_soc_pcm_runtime' from 'struct snd_pcm_substream' opaque pointer private_data field with snd_soc_substream_to_rtd(). However 'private_data' appears in several other structures as well, including 'struct snd_compr_stream'. The field might not hold the same type for every structure, although seems the case at least for 'struct snd_compr_stream', so code can easily make a mistake by using macro for wrong structure passed as argument. Switch from macro to inline function, so such mistake will be build-time detectable. Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 9f6bdb0 commit 9723cab

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/sound/soc.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,12 @@ struct snd_soc_pcm_runtime {
12151215
/* see soc_new_pcm_runtime() */
12161216
#define snd_soc_rtd_to_cpu(rtd, n) (rtd)->dais[n]
12171217
#define snd_soc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->dai_link->num_cpus]
1218-
#define snd_soc_substream_to_rtd(substream) \
1219-
(struct snd_soc_pcm_runtime *)snd_pcm_substream_chip(substream)
1218+
1219+
static inline struct snd_soc_pcm_runtime *
1220+
snd_soc_substream_to_rtd(const struct snd_pcm_substream *substream)
1221+
{
1222+
return snd_pcm_substream_chip(substream);
1223+
}
12201224

12211225
#define for_each_rtd_components(rtd, i, component) \
12221226
for ((i) = 0, component = NULL; \

0 commit comments

Comments
 (0)