diff mbox series

[1/2] ASoC: soc-compress: tidyup STREAM vs COMPRESS

Message ID 87v9ewfnj9.wl-kuninori.morimoto.gx@renesas.com
State Superseded
Headers show
Series ASoC: soc-compress: tidyup STREAM vs COMPRESS | expand

Commit Message

Kuninori Morimoto Oct. 27, 2020, 1:51 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

snd_soc_runtime_activate() and
snd_soc_dai_digital_mute() need SNDRV_PCM_STREAM_xxx
instead of SND_COMPRESS_xxx.

These are bug but nothing happen because these are same value.

	enum {
		SNDRV_PCM_STREAM_PLAYBACK = 0,
		SNDRV_PCM_STREAM_CAPTURE,
		...
	};

	enum snd_compr_direction {
		SND_COMPRESS_PLAYBACK = 0,
		SND_COMPRESS_CAPTURE
	};

This patch tidyup it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-compress.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

Comments

Kuninori Morimoto Oct. 28, 2020, 11:23 p.m. UTC | #1
Hi Pierre-Louis
Cc Mark

> > From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> > 
> > snd_soc_runtime_activate() and
> > snd_soc_dai_digital_mute() need SNDRV_PCM_STREAM_xxx
> > instead of SND_COMPRESS_xxx.
> > 
> > These are bug but nothing happen because these are same value.
> > 
> > 	enum {
> > 		SNDRV_PCM_STREAM_PLAYBACK = 0,
> > 		SNDRV_PCM_STREAM_CAPTURE,
> > 		...
> > 	};
> > 
> > 	enum snd_compr_direction {
> > 		SND_COMPRESS_PLAYBACK = 0,
> > 		SND_COMPRESS_CAPTURE
> > 	};
> > 
> > This patch tidyup it.
> 
> 
> Could we use this instead:
> 
> enum snd_compr_direction {
> 	SND_COMPRESS_PLAYBACK = SNDRV_PCM_STREAM_PLAYBACK,
> 	SND_COMPRESS_CAPTURE = SNDRV_PCM_STREAM_CAPTURE
> };
> 
> Or remove this duplication completely and get rid of snd_compr_direction?
> 
> I find it odd to convert two things that had no reason to be different
> in the first place.

Yes I agree with you.
I'm not sure why this duplication was created,
but my patch tried to make it sane.
If Mark can agree, I can post snd_compr_direction remove patch.


Thank you for your help !!

Best regards
---
Kuninori Morimoto
Kuninori Morimoto Oct. 28, 2020, 11:43 p.m. UTC | #2
Hi Pierre-Louis, again

> > enum snd_compr_direction {
> > 	SND_COMPRESS_PLAYBACK = SNDRV_PCM_STREAM_PLAYBACK,
> > 	SND_COMPRESS_CAPTURE = SNDRV_PCM_STREAM_CAPTURE
> > };
> > 
> > Or remove this duplication completely and get rid of snd_compr_direction?
> > 
> > I find it odd to convert two things that had no reason to be different
> > in the first place.
> 
> Yes I agree with you.
> I'm not sure why this duplication was created,
> but my patch tried to make it sane.
> If Mark can agree, I can post snd_compr_direction remove patch.

Oops, snd_compr_direction was uapi.
We can't remove it, and can't use your above suggestion...

Thank you for your help !!

Best regards
---
Kuninori Morimoto
Takashi Iwai Oct. 29, 2020, 7:04 a.m. UTC | #3
On Thu, 29 Oct 2020 00:43:08 +0100,
Kuninori Morimoto wrote:
> 
> 
> Hi Pierre-Louis, again
> 
> > > enum snd_compr_direction {
> > > 	SND_COMPRESS_PLAYBACK = SNDRV_PCM_STREAM_PLAYBACK,
> > > 	SND_COMPRESS_CAPTURE = SNDRV_PCM_STREAM_CAPTURE
> > > };
> > > 
> > > Or remove this duplication completely and get rid of snd_compr_direction?
> > > 
> > > I find it odd to convert two things that had no reason to be different
> > > in the first place.
> > 
> > Yes I agree with you.
> > I'm not sure why this duplication was created,
> > but my patch tried to make it sane.
> > If Mark can agree, I can post snd_compr_direction remove patch.
> 
> Oops, snd_compr_direction was uapi.
> We can't remove it, and can't use your above suggestion...

Right, such uapi can't be removed.

Essentially both compress and PCM definitions are identical, and can
be never different because of ABI compatibility, which means it's safe
to mix both variants in the code.  If you're unsure, we may add
BUILD_BUG_ON() to check the coincidence of both values.


thanks,

Takashi
Pierre-Louis Bossart Oct. 29, 2020, 3:33 p.m. UTC | #4
>>>> enum snd_compr_direction {
>>>> 	SND_COMPRESS_PLAYBACK = SNDRV_PCM_STREAM_PLAYBACK,
>>>> 	SND_COMPRESS_CAPTURE = SNDRV_PCM_STREAM_CAPTURE
>>>> };
>>>>
>>>> Or remove this duplication completely and get rid of snd_compr_direction?
>>>>
>>>> I find it odd to convert two things that had no reason to be different
>>>> in the first place.
>>>
>>> Yes I agree with you.
>>> I'm not sure why this duplication was created,
>>> but my patch tried to make it sane.
>>> If Mark can agree, I can post snd_compr_direction remove patch.
>>
>> Oops, snd_compr_direction was uapi.
>> We can't remove it, and can't use your above suggestion...

I knew I was missing something... Thanks for correcting my flawed assertion.

> Right, such uapi can't be removed.
> 
> Essentially both compress and PCM definitions are identical, and can
> be never different because of ABI compatibility, which means it's safe
> to mix both variants in the code.  If you're unsure, we may add
> BUILD_BUG_ON() to check the coincidence of both values.


In case we add this BUILD_BUG_ON(), can we keep the code as is then, 
there's no need to convert values?
Takashi Iwai Oct. 29, 2020, 4:47 p.m. UTC | #5
On Thu, 29 Oct 2020 16:33:35 +0100,
Pierre-Louis Bossart wrote:
> 
> 
> 
> 
> >>>> enum snd_compr_direction {
> >>>> 	SND_COMPRESS_PLAYBACK = SNDRV_PCM_STREAM_PLAYBACK,
> >>>> 	SND_COMPRESS_CAPTURE = SNDRV_PCM_STREAM_CAPTURE
> >>>> };
> >>>>
> >>>> Or remove this duplication completely and get rid of snd_compr_direction?
> >>>>
> >>>> I find it odd to convert two things that had no reason to be different
> >>>> in the first place.
> >>>
> >>> Yes I agree with you.
> >>> I'm not sure why this duplication was created,
> >>> but my patch tried to make it sane.
> >>> If Mark can agree, I can post snd_compr_direction remove patch.
> >>
> >> Oops, snd_compr_direction was uapi.
> >> We can't remove it, and can't use your above suggestion...
> 
> I knew I was missing something... Thanks for correcting my flawed assertion.
> 
> > Right, such uapi can't be removed.
> >
> > Essentially both compress and PCM definitions are identical, and can
> > be never different because of ABI compatibility, which means it's safe
> > to mix both variants in the code.  If you're unsure, we may add
> > BUILD_BUG_ON() to check the coincidence of both values.
> 
> 
> In case we add this BUILD_BUG_ON(), can we keep the code as is then,
> there's no need to convert values?

Unless any strong type is used, it should be fine as is.
BUILD_BUG_ON() would catch if the value is changed inconsistently.


thanks,

Takashi
Kuninori Morimoto Oct. 30, 2020, 12:48 a.m. UTC | #6
Hi

> > > Right, such uapi can't be removed.
> > >
> > > Essentially both compress and PCM definitions are identical, and can
> > > be never different because of ABI compatibility, which means it's safe
> > > to mix both variants in the code.  If you're unsure, we may add
> > > BUILD_BUG_ON() to check the coincidence of both values.
> > 
> > 
> > In case we add this BUILD_BUG_ON(), can we keep the code as is then,
> > there's no need to convert values?
> 
> Unless any strong type is used, it should be fine as is.
> BUILD_BUG_ON() would catch if the value is changed inconsistently.

OK, Thanks.
v2 Will use BUILD_BUG_ON().

Thank you for your help !!

Best regards
---
Kuninori Morimoto
diff mbox series

Patch

diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 3a6a60215e81..52544a85725d 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -75,8 +75,14 @@  static int soc_compr_open(struct snd_compr_stream *cstream)
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_component *component = NULL;
 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+	int stream;
 	int ret;
 
+	if (cstream->direction == SND_COMPRESS_PLAYBACK)
+		stream = SNDRV_PCM_STREAM_PLAYBACK;
+	else
+		stream = SNDRV_PCM_STREAM_CAPTURE;
+
 	ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream);
 	if (ret < 0)
 		goto pm_err;
@@ -95,7 +101,7 @@  static int soc_compr_open(struct snd_compr_stream *cstream)
 	if (ret < 0)
 		goto machine_err;
 
-	snd_soc_runtime_activate(rtd, cstream->direction);
+	snd_soc_runtime_activate(rtd, stream);
 
 	mutex_unlock(&rtd->card->pcm_mutex);
 
@@ -208,7 +214,7 @@  static int soc_compr_free(struct snd_compr_stream *cstream)
 
 	snd_soc_runtime_deactivate(rtd, stream);
 
-	snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
+	snd_soc_dai_digital_mute(codec_dai, 1, stream);
 
 	if (!snd_soc_dai_active(cpu_dai))
 		cpu_dai->rate = 0;
@@ -304,10 +310,16 @@  static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+	int stream;
 	int ret;
 
 	mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
 
+	if (cstream->direction == SND_COMPRESS_PLAYBACK)
+		stream = SNDRV_PCM_STREAM_PLAYBACK;
+	else
+		stream = SNDRV_PCM_STREAM_CAPTURE;
+
 	ret = soc_compr_components_trigger(cstream, cmd);
 	if (ret < 0)
 		goto out;
@@ -318,10 +330,10 @@  static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
-		snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction);
+		snd_soc_dai_digital_mute(codec_dai, 0, stream);
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
-		snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
+		snd_soc_dai_digital_mute(codec_dai, 1, stream);
 		break;
 	}