Skip to contentSkip to conversation

staging: greybus: audio: Add missing unlock in gbaudio_dapm_free_controls()

PATCH In review Wang Hai 3 participants 6 messages Dec 4, 2020 – Dec 5, 2020

Subsystems (2)
lore
Share & tools
lore

Wang Hai

author
#0 lore raw

PATCH 1/1 staging: greybus: audio: Add missing unlock in gbaudio_dapm_free_controls()

Add the missing unlock before return from function gbaudio_dapm_free_controls() in the error handling case.

Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio module")
---
 drivers/staging/greybus/audio_helper.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/greybus/audio_helper.c +1 -0
index 237531ba60f3..293675dbea10 100644
@@ -135,6 +135,7 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
 		if (!w) {
 			dev_err(dapm->dev, "%s: widget not found\n",
 				widget->name);
+			mutex_unlock(&dapm->card->dapm_mutex);
 			return -EINVAL;
 		}
 		widget++;
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 15 lines · Wang Hai

Add the missing unlock before return from function gbaudio_dapm_free_controls() in the error handling case.

Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio module")
---
 drivers/staging/greybus/audio_helper.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/greybus/audio_helper.c +0 -0
index 237531ba60f3..293675dbea10 100644

drivers/staging/greybus/audio_helper.c int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm, · line 141

Quoted 7 lines
drivers/staging/greybus/audio_helper.c +1 -0
@@ -135,6 +135,7 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
 		if (!w) {
 			dev_err(dapm->dev, "%s: widget not found\n",
 				widget->name);
+			mutex_unlock(&dapm->card->dapm_mutex);
 			return -EINVAL;
 		}
 		widget++;

This superficially looks correct, but there seems to be another bug in this function. It can be used free an array of widgets, but if one of them isn't found we just leak the rest. Perhaps that return should rather be "widget++; continue;".

Vaibhav?

Johan

#2 lore raw
Quoted 11 lines · Johan Hovold
Quoted 10 lines · Wang Hai

Add the missing unlock before return from function gbaudio_dapm_free_controls() in the error handling case.

Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio module")
---
  drivers/staging/greybus/audio_helper.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 17 lines

drivers/staging/greybus/audio_helper.c int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm, · line 141

Quoted 12 lines
drivers/staging/greybus/audio_helper.c +1 -0
index 237531ba60f3..293675dbea10 100644
@@ -135,6 +135,7 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
  		if (!w) {
  			dev_err(dapm->dev, "%s: widget not found\n",
  				widget->name);
+			mutex_unlock(&dapm->card->dapm_mutex);
  			return -EINVAL;
  		}
  		widget++;

This superficially looks correct, but there seems to be another bug in this function. It can be used free an array of widgets, but if one of them isn't found we just leak the rest. Perhaps that return should rather be "widget++; continue;".

I think this is a good idea, should I send a v2 patch?

Quoted 1 line
maintainer
#3 lore raw
Quoted 30 lines · wanghai (M)
Quoted 11 lines · Johan Hovold
Quoted 10 lines · Wang Hai

Add the missing unlock before return from function gbaudio_dapm_free_controls() in the error handling case.

Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio module")
---
  drivers/staging/greybus/audio_helper.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 17 lines

drivers/staging/greybus/audio_helper.c int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm, · line 141

Quoted 12 lines
drivers/staging/greybus/audio_helper.c +1 -0
index 237531ba60f3..293675dbea10 100644
@@ -135,6 +135,7 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
  		if (!w) {
  			dev_err(dapm->dev, "%s: widget not found\n",
  				widget->name);
+			mutex_unlock(&dapm->card->dapm_mutex);
  			return -EINVAL;
  		}
  		widget++;

This superficially looks correct, but there seems to be another bug in this function. It can be used free an array of widgets, but if one of them isn't found we just leak the rest. Perhaps that return should rather be "widget++; continue;".

Quoted 1 line

I think this is a good idea, should I send a v2 patch?

Let's just wait a bit and see what Vaibhav or Mark says first.

Johan

#4 lore raw
In reply to Johan Hovold
Quoted 30 lines · Johan Hovold
Quoted 15 lines · Wang Hai

Add the missing unlock before return from function gbaudio_dapm_free_controls() in the error handling case.

Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio module")
---
 drivers/staging/greybus/audio_helper.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/greybus/audio_helper.c +0 -0
index 237531ba60f3..293675dbea10 100644

drivers/staging/greybus/audio_helper.c int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm, · line 141

Quoted 7 lines
drivers/staging/greybus/audio_helper.c +1 -0
@@ -135,6 +135,7 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
              if (!w) {
                      dev_err(dapm->dev, "%s: widget not found\n",
                              widget->name);
+                     mutex_unlock(&dapm->card->dapm_mutex);
                      return -EINVAL;
              }
              widget++;

This superficially looks correct, but there seems to be another bug in this function. It can be used free an array of widgets, but if one of them isn't found we just leak the rest. Perhaps that return should rather be "widget++; continue;".

Quoted 1 line

Vaibhav?

Thanks Wang for sharing the patch. As already pointed by Johan, this function indeed has another bug as well.
Pls feel free to share the patch as suggested above.

--
vaibhav

Quoted 2 lines

Johan

#5 lore raw
Quoted 29 lines · Vaibhav Agarwal
Quoted 28 lines · Johan Hovold
Quoted 15 lines · Wang Hai

Add the missing unlock before return from function gbaudio_dapm_free_controls() in the error handling case.

Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio module")
---
  drivers/staging/greybus/audio_helper.c | 1 +
  1 file changed, 1 insertion(+)
drivers/staging/greybus/audio_helper.c +0 -0
index 237531ba60f3..293675dbea10 100644

drivers/staging/greybus/audio_helper.c int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm, · line 141

Quoted 7 lines
drivers/staging/greybus/audio_helper.c +1 -0
@@ -135,6 +135,7 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm,
               if (!w) {
                       dev_err(dapm->dev, "%s: widget not found\n",
                               widget->name);
+                     mutex_unlock(&dapm->card->dapm_mutex);
                       return -EINVAL;
               }
               widget++;

This superficially looks correct, but there seems to be another bug in this function. It can be used free an array of widgets, but if one of them isn't found we just leak the rest. Perhaps that return should rather be "widget++; continue;".

Quoted 4 lines
Quoted 1 line

Vaibhav?

Thanks Wang for sharing the patch. As already pointed by Johan, this function indeed has another bug as well.
Pls feel free to share the patch as suggested above.

I just sent another patch

"[PATCH] staging: greybus: audio: Fix possible leak free widgets in gbaudio_dapm_free_controls"

Quoted 3 lines

Johan
.