ASoC: Use inline function for type safety in snd_soc_substream_to_rtd()
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Wed, 1 May 2024 17:51:27 +0000 (19:51 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 2 May 2024 03:57:25 +0000 (12:57 +0900)
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 <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240501175127.34301-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc.h

index 8aa6ddb7ee1e8955af52a28ebfbfa93aabf9d17b..33671437ee896ee694f8880eba1b007f5ab16c28 100644 (file)
@@ -1215,8 +1215,12 @@ struct snd_soc_pcm_runtime {
 /* see soc_new_pcm_runtime()  */
 #define snd_soc_rtd_to_cpu(rtd, n)   (rtd)->dais[n]
 #define snd_soc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->dai_link->num_cpus]
-#define snd_soc_substream_to_rtd(substream) \
-       (struct snd_soc_pcm_runtime *)snd_pcm_substream_chip(substream)
+
+static inline struct snd_soc_pcm_runtime *
+snd_soc_substream_to_rtd(const struct snd_pcm_substream *substream)
+{
+       return snd_pcm_substream_chip(substream);
+}
 
 #define for_each_rtd_components(rtd, i, component)                     \
        for ((i) = 0, component = NULL;                                 \