LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: fsl-asoc-card: Fix jack_event() always return 0
@ 2022-03-18  9:35 Meng Tang
  2022-03-20 13:01 ` Shengjiu Wang
  2022-03-21  6:44 ` Christophe Leroy
  0 siblings, 2 replies; 3+ messages in thread
From: Meng Tang @ 2022-03-18  9:35 UTC (permalink / raw)
  To: nicoleotsuka, Xiubo.Lee, festevam, shengjiu.wang, lgirdwood,
	broonie, perex, tiwai
  Cc: Meng Tang, alsa-devel, linuxppc-dev, linux-kernel

Today, hp_jack_event and mic_jack_event always return 0. However,
snd_soc_dapm_disable_pin and snd_soc_dapm_enable_pin may return a
non-zero value, this will cause the user who calling hp_jack_event
and mic_jack_event don't know whether the operation was really
successfully.

This patch corrects the behavior by properly returning 1 when the
value gets updated.

Signed-off-by: Meng Tang <tangmeng@uniontech.com>
---
 sound/soc/fsl/fsl-asoc-card.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index 370bc790c6ba..f2641c2cb047 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -457,16 +457,18 @@ static int fsl_asoc_card_audmux_init(struct device_node *np,
 static int hp_jack_event(struct notifier_block *nb, unsigned long event,
 			 void *data)
 {
+	int ret;
+
 	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
 	struct snd_soc_dapm_context *dapm = &jack->card->dapm;
 
 	if (event & SND_JACK_HEADPHONE)
 		/* Disable speaker if headphone is plugged in */
-		snd_soc_dapm_disable_pin(dapm, "Ext Spk");
+		ret = snd_soc_dapm_disable_pin(dapm, "Ext Spk");
 	else
-		snd_soc_dapm_enable_pin(dapm, "Ext Spk");
+		ret = snd_soc_dapm_enable_pin(dapm, "Ext Spk");
 
-	return 0;
+	return ret;
 }
 
 static struct notifier_block hp_jack_nb = {
@@ -476,16 +478,18 @@ static struct notifier_block hp_jack_nb = {
 static int mic_jack_event(struct notifier_block *nb, unsigned long event,
 			  void *data)
 {
+	int ret;
+
 	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
 	struct snd_soc_dapm_context *dapm = &jack->card->dapm;
 
 	if (event & SND_JACK_MICROPHONE)
 		/* Disable dmic if microphone is plugged in */
-		snd_soc_dapm_disable_pin(dapm, "DMIC");
+		ret = snd_soc_dapm_disable_pin(dapm, "DMIC");
 	else
-		snd_soc_dapm_enable_pin(dapm, "DMIC");
+		ret = snd_soc_dapm_enable_pin(dapm, "DMIC");
 
-	return 0;
+	return ret;
 }
 
 static struct notifier_block mic_jack_nb = {
-- 
2.20.1




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

* Re: [PATCH] ASoC: fsl-asoc-card: Fix jack_event() always return 0
  2022-03-18  9:35 [PATCH] ASoC: fsl-asoc-card: Fix jack_event() always return 0 Meng Tang
@ 2022-03-20 13:01 ` Shengjiu Wang
  2022-03-21  6:44 ` Christophe Leroy
  1 sibling, 0 replies; 3+ messages in thread
From: Shengjiu Wang @ 2022-03-20 13:01 UTC (permalink / raw)
  To: Meng Tang
  Cc: alsa-devel, Xiubo Li, linuxppc-dev, Takashi Iwai, Liam Girdwood,
	Jaroslav Kysela, Nicolin Chen, Mark Brown, Fabio Estevam,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2612 bytes --]

Hi

On Fri, Mar 18, 2022 at 5:35 PM Meng Tang <tangmeng@uniontech.com> wrote:

> Today, hp_jack_event and mic_jack_event always return 0. However,
> snd_soc_dapm_disable_pin and snd_soc_dapm_enable_pin may return a
> non-zero value, this will cause the user who calling hp_jack_event
> and mic_jack_event don't know whether the operation was really
> successfully.
>
> This patch corrects the behavior by properly returning 1 when the
> value gets updated.
>
> Signed-off-by: Meng Tang <tangmeng@uniontech.com>
> ---
>  sound/soc/fsl/fsl-asoc-card.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
> index 370bc790c6ba..f2641c2cb047 100644
> --- a/sound/soc/fsl/fsl-asoc-card.c
> +++ b/sound/soc/fsl/fsl-asoc-card.c
> @@ -457,16 +457,18 @@ static int fsl_asoc_card_audmux_init(struct
> device_node *np,
>  static int hp_jack_event(struct notifier_block *nb, unsigned long event,
>                          void *data)
>  {
> +       int ret;
> +
>         struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
>         struct snd_soc_dapm_context *dapm = &jack->card->dapm;

The "int ret" should be here.
The variables have order, the short one should be behind the long one.


>




>         if (event & SND_JACK_HEADPHONE)
>                 /* Disable speaker if headphone is plugged in */
> -               snd_soc_dapm_disable_pin(dapm, "Ext Spk");
> +               ret = snd_soc_dapm_disable_pin(dapm, "Ext Spk");
>         else
> -               snd_soc_dapm_enable_pin(dapm, "Ext Spk");
> +               ret = snd_soc_dapm_enable_pin(dapm, "Ext Spk");
>
> -       return 0;
> +       return ret;
>  }
>
>  static struct notifier_block hp_jack_nb = {
> @@ -476,16 +478,18 @@ static struct notifier_block hp_jack_nb = {
>  static int mic_jack_event(struct notifier_block *nb, unsigned long event,
>                           void *data)
>  {
> +       int ret;
> +
>         struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
>         struct snd_soc_dapm_context *dapm = &jack->card->dapm;
>
ditto.

>
>         if (event & SND_JACK_MICROPHONE)
>                 /* Disable dmic if microphone is plugged in */
> -               snd_soc_dapm_disable_pin(dapm, "DMIC");
> +               ret = snd_soc_dapm_disable_pin(dapm, "DMIC");
>         else
> -               snd_soc_dapm_enable_pin(dapm, "DMIC");
> +               ret = snd_soc_dapm_enable_pin(dapm, "DMIC");
>
> -       return 0;
> +       return ret;
>  }
>
>  static struct notifier_block mic_jack_nb = {
> --
> 2.20.1
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 4046 bytes --]

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

* Re: [PATCH] ASoC: fsl-asoc-card: Fix jack_event() always return 0
  2022-03-18  9:35 [PATCH] ASoC: fsl-asoc-card: Fix jack_event() always return 0 Meng Tang
  2022-03-20 13:01 ` Shengjiu Wang
@ 2022-03-21  6:44 ` Christophe Leroy
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-03-21  6:44 UTC (permalink / raw)
  To: Meng Tang, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com,
	festevam@gmail.com, shengjiu.wang@gmail.com, lgirdwood@gmail.com,
	broonie@kernel.org, perex@perex.cz, tiwai@suse.com
  Cc: alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org,
	linux-kernel@vger.kernel.org



Le 18/03/2022 à 10:35, Meng Tang a écrit :
> Today, hp_jack_event and mic_jack_event always return 0. However,
> snd_soc_dapm_disable_pin and snd_soc_dapm_enable_pin may return a
> non-zero value, this will cause the user who calling hp_jack_event
> and mic_jack_event don't know whether the operation was really
> successfully.
> 
> This patch corrects the behavior by properly returning 1 when the
> value gets updated.
> 
> Signed-off-by: Meng Tang <tangmeng@uniontech.com>
> ---
>   sound/soc/fsl/fsl-asoc-card.c | 16 ++++++++++------
>   1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
> index 370bc790c6ba..f2641c2cb047 100644
> --- a/sound/soc/fsl/fsl-asoc-card.c
> +++ b/sound/soc/fsl/fsl-asoc-card.c
> @@ -457,16 +457,18 @@ static int fsl_asoc_card_audmux_init(struct device_node *np,
>   static int hp_jack_event(struct notifier_block *nb, unsigned long event,
>   			 void *data)
>   {
> +	int ret;
> +

You don't need that new local var. There are coccinelle scripts that 
track those unnecessary intermediates so don't add a new one.

>   	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
>   	struct snd_soc_dapm_context *dapm = &jack->card->dapm;
>   
>   	if (event & SND_JACK_HEADPHONE)
>   		/* Disable speaker if headphone is plugged in */
> -		snd_soc_dapm_disable_pin(dapm, "Ext Spk");
> +		ret = snd_soc_dapm_disable_pin(dapm, "Ext Spk");

Should be
		return snd_soc_dapm_disable_pin(dapm, "Ext Spk");

>   	else
> -		snd_soc_dapm_enable_pin(dapm, "Ext Spk");
> +		ret = snd_soc_dapm_enable_pin(dapm, "Ext Spk");

and

		return snd_soc_dapm_enable_pin(dapm, "Ext Spk");

>   
> -	return 0;
> +	return ret;

And completely drop that.

>   }
>   
>   static struct notifier_block hp_jack_nb = {
> @@ -476,16 +478,18 @@ static struct notifier_block hp_jack_nb = {
>   static int mic_jack_event(struct notifier_block *nb, unsigned long event,
>   			  void *data)
>   {
> +	int ret;
> +

And do exactly the same here.

>   	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
>   	struct snd_soc_dapm_context *dapm = &jack->card->dapm;
>   
>   	if (event & SND_JACK_MICROPHONE)
>   		/* Disable dmic if microphone is plugged in */
> -		snd_soc_dapm_disable_pin(dapm, "DMIC");
> +		ret = snd_soc_dapm_disable_pin(dapm, "DMIC");
>   	else
> -		snd_soc_dapm_enable_pin(dapm, "DMIC");
> +		ret = snd_soc_dapm_enable_pin(dapm, "DMIC");
>   
> -	return 0;
> +	return ret;
>   }
>   
>   static struct notifier_block mic_jack_nb = {

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

end of thread, other threads:[~2022-03-21  6:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-18  9:35 [PATCH] ASoC: fsl-asoc-card: Fix jack_event() always return 0 Meng Tang
2022-03-20 13:01 ` Shengjiu Wang
2022-03-21  6:44 ` Christophe Leroy

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