Skip to contentSkip to conversation

ASoC: fsl-asoc-card: Fix jack_event() always return 0

PATCH Superseded Meng Tang 3 participants 3 messages Mar 18, 2022 – Mar 21, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Meng Tang

author
#0 lore raw

PATCH 1/1 ASoC: fsl-asoc-card: Fix jack_event() always return 0

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.

---
 sound/soc/fsl/fsl-asoc-card.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
sound/soc/fsl/fsl-asoc-card.c +10 -6
index 370bc790c6ba..f2641c2cb047 100644
@@ -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 = {
Signature · 1 line
2.20.1
maintainer
#1 lore raw

Hi

Quoted 19 lines · Meng Tang

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.

---
 sound/soc/fsl/fsl-asoc-card.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
sound/soc/fsl/fsl-asoc-card.c +0 -0
index 370bc790c6ba..f2641c2cb047 100644

sound/soc/fsl/fsl-asoc-card.c static int fsl_asoc_card_audmux_init(struct · line 464

Quoted 8 lines
sound/soc/fsl/fsl-asoc-card.c +2 -0
@@ -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.

Quoted 19 lines
sound/soc/fsl/fsl-asoc-card.c +3 -3
        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 = {

sound/soc/fsl/fsl-asoc-card.c static struct notifier_block hp_jack_nb = { · line 485

Quoted 8 lines
sound/soc/fsl/fsl-asoc-card.c +2 -0
@@ -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.

Quoted 20 lines
sound/soc/fsl/fsl-asoc-card.c +3 -4
        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

#2 lore raw
In reply to Meng Tang

Le 18/03/2022 à 10:35, Meng Tang a écrit :

Quoted 19 lines

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.

---
  sound/soc/fsl/fsl-asoc-card.c | 16 ++++++++++------
  1 file changed, 10 insertions(+), 6 deletions(-)
sound/soc/fsl/fsl-asoc-card.c +0 -0
index 370bc790c6ba..f2641c2cb047 100644

sound/soc/fsl/fsl-asoc-card.c static int fsl_asoc_card_audmux_init(struct device_node *np, · line 461

Quoted 5 lines
sound/soc/fsl/fsl-asoc-card.c +2 -0
@@ -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.

sound/soc/fsl/fsl-asoc-card.c static int fsl_asoc_card_audmux_init(struct device_node *np, · line 467

Quoted 7 lines
sound/soc/fsl/fsl-asoc-card.c +1 -1
  	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");

sound/soc/fsl/fsl-asoc-card.c static int fsl_asoc_card_audmux_init(struct device_node *np, · line 469

Quoted 3 lines
sound/soc/fsl/fsl-asoc-card.c +1 -1
  	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");

sound/soc/fsl/fsl-asoc-card.c static int fsl_asoc_card_audmux_init(struct device_node *np, · line 470

Quoted 3 lines
sound/soc/fsl/fsl-asoc-card.c +1 -1
-	return 0;
+	return ret;

And completely drop that.

sound/soc/fsl/fsl-asoc-card.c static struct notifier_block hp_jack_nb = { · line 482

Quoted 9 lines
sound/soc/fsl/fsl-asoc-card.c +2 -0
  }
 
  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.

Quoted 16 lines
sound/soc/fsl/fsl-asoc-card.c +3 -3
  	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 = {