Hi Amadeusz
Thank you for your help
My mistake in example, I've used function syntax, notice (x) at the end, if you remove it, it seems to build without need to call inline functions:
Thanks. I was aware of that.
Your example is calling snd_pcm_is_playback() with "snd_pcm_substream" only. It works well indeed. But I will get error if I call it with "int", like below. I don't know how to solve this issue and/or what does it mean...
${LINUX}/sound/soc/intel/avs/pcm.c: In function 'avs_dai_hda_be_prepare': ${LINUX}/include/sound/pcm.h:506:40: error: invalid type argument of '->' (have 'int') 506 | struct snd_pcm_substream * : ((x)->stream == SNDRV_PCM_STREAM_PLAYBACK)) | ^~ ${LINUX}/sound/soc/intel/avs/pcm.c:375:13: note: in expansion of macro 'snd_pcm_is_playback' 375 | if (snd_pcm_is_playback(substream->stream)) | ^~~~~~~~~~~~~~~~~~~
Below is the code. It is copied your example, and I updated it to use both "int" and "snd_pcm_substream".
- if (snd_pcm_is_playback(substream)) + if (snd_pcm_is_playback(substream->stream))
---------------- diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 3edd7a7346da..a4916342f715 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -501,6 +501,9 @@ struct snd_pcm_substream {
#define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
+#define snd_pcm_is_playback(x) _Generic((x), \ + int : ((x) == SNDRV_PCM_STREAM_PLAYBACK), \ + struct snd_pcm_substream * : ((x)->stream == SNDRV_PCM_STREAM_PLAYBACK))
struct snd_pcm_str { int stream; /* stream (direction) */ diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c index c76b86254a8b..79ae6a5df9c2 100644 --- a/sound/soc/intel/avs/pcm.c +++ b/sound/soc/intel/avs/pcm.c @@ -331,7 +331,7 @@ static int avs_dai_hda_be_hw_free(struct snd_pcm_substream *substream, struct sn if (!link) return -EINVAL;
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + if (snd_pcm_is_playback(substream)) snd_hdac_ext_bus_link_clear_stream_id(link, hdac_stream(link_stream)->stream_tag);
return 0; @@ -372,7 +372,7 @@ static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct sn if (!link) return -EINVAL;
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + if (snd_pcm_is_playback(substream->stream)) snd_hdac_ext_bus_link_set_stream_id(link, hdac_stream(link_stream)->stream_tag);
ret = avs_dai_prepare(substream, dai); ----------------
Thank you for your help !!
Best regards --- Kuninori Morimoto