Skip to contentSkip to conversation

ASoC: wm0010: disable regulator on error

PATCH In review Sudip Mukherjee 3 participants 10 messages Sep 18, 2015 – Sep 20, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ASoC: wm0010: disable regulator on error

We have done regulator_bulk_enable() while booting the DSP but on the error exit path we have not disbled it.

---
 sound/soc/codecs/wm0010.c | 2 --
 1 file changed, 2 deletions(-)
sound/soc/codecs/wm0010.c +0 -2
index 8434d45..79a7cd3 100644
@@ -739,8 +739,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 abort:
 	/* Put the chip back into reset */
 	wm0010_halt(codec);
-	mutex_unlock(&wm0010->lock);
-	return ret;
 
 err_core:
 	mutex_unlock(&wm0010->lock);
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/3 ASoC: wm0010: fix memory leak

We have requested for the firmware but we have missed releasing it both on success and on error path.
While checking the code it turned out that the requested firmware is not even used. More over the same firmware is being loaded by wm0010_stage2_load().

---
 sound/soc/codecs/wm0010.c | 9 ---------
 1 file changed, 9 deletions(-)
sound/soc/codecs/wm0010.c +0 -9
index 79a7cd3..4947be5 100644
@@ -577,7 +577,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 	struct wm0010_priv *wm0010 = snd_soc_codec_get_drvdata(codec);
 	unsigned long flags;
 	int ret;
-	const struct firmware *fw;
 	struct spi_message m;
 	struct spi_transfer t;
 	struct dfw_pllrec pll_rec;
@@ -623,14 +622,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 	wm0010->state = WM0010_OUT_OF_RESET;
 	spin_unlock_irqrestore(&wm0010->irq_lock, flags);
 
-	/* First the bootloader */
-	ret = request_firmware(&fw, "wm0010_stage2.bin", codec->dev);
-	if (ret != 0) {
-		dev_err(codec->dev, "Failed to request stage2 loader: %d\n",
-			ret);
-		goto abort;
-	}
-
 	if (!wait_for_completion_timeout(&wm0010->boot_completion,
 					 msecs_to_jiffies(20)))
 		dev_err(codec->dev, "Failed to get interrupt from DSP\n");
Signature · 1 line
1.9.1
Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] ASoC: wm0010: fix memory leak

Quoted 8 lines · Sudip Mukherjee

We have requested for the firmware but we have missed releasing it both on success and on error path.
While checking the code it turned out that the requested firmware is not even used. More over the same firmware is being loaded by wm0010_stage2_load().

---

hmm... odd guess this must have been missed when
wm0010_stage2_load was created.

Thanks,
Charles

maintainer
#3 lore raw

Applied "ASoC: wm0010: fix memory leak" to the asoc tree

In reply to Sudip Mukherjee

The patch

ASoC: wm0010: fix memory leak

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 2ace47be5a315def8f493ca77aa59c077ade30a1 Mon Sep 17 00:00:00 2001

From: Sudip Mukherjee <[email protected]>
Date: Fri, 18 Sep 2015 16:02:20 +0530
Subject: [PATCH] ASoC: wm0010: fix memory leak

We have requested for the firmware but we have missed releasing it both on success and on error path.
While checking the code it turned out that the requested firmware is not even used. More over the same firmware is being loaded by wm0010_stage2_load().

---
 sound/soc/codecs/wm0010.c | 9 ---------
 1 file changed, 9 deletions(-)
sound/soc/codecs/wm0010.c +0 -9
index 9d370a4..7a1bc40 100644
@@ -577,7 +577,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 	struct wm0010_priv *wm0010 = snd_soc_codec_get_drvdata(codec);
 	unsigned long flags;
 	int ret;
-	const struct firmware *fw;
 	struct spi_message m;
 	struct spi_transfer t;
 	struct dfw_pllrec pll_rec;
@@ -623,14 +622,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 	wm0010->state = WM0010_OUT_OF_RESET;
 	spin_unlock_irqrestore(&wm0010->irq_lock, flags);
 
-	/* First the bootloader */
-	ret = request_firmware(&fw, "wm0010_stage2.bin", codec->dev);
-	if (ret != 0) {
-		dev_err(codec->dev, "Failed to request stage2 loader: %d\n",
-			ret);
-		goto abort;
-	}
-
 	if (!wait_for_completion_timeout(&wm0010->boot_completion,
 					 msecs_to_jiffies(20)))
 		dev_err(codec->dev, "Failed to get interrupt from DSP\n");
Signature · 1 line
2.5.0
#4 lore raw

PATCH 3/3 ASoC: wm0010: fix error path

In reply to Sudip Mukherjee

Fix the error path so that we can free the allocated memory on the error path instead of releasing them individually on each error.

---
 sound/soc/codecs/wm0010.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
sound/soc/codecs/wm0010.c +10 -12
index 4947be5..3ced902 100644
@@ -663,10 +663,8 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 		}
 
 		img_swap = kzalloc(len, GFP_KERNEL | GFP_DMA);
-		if (!img_swap) {
-			kfree(out);
-			goto abort;
-		}
+		if (!img_swap)
+			goto abort_out;
 
 		/* We need to re-order for 0010 */
 		byte_swap_64((u64 *)&pll_rec, img_swap, len);
@@ -681,20 +679,16 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 		spi_message_add_tail(&t, &m);
 
 		ret = spi_sync(spi, &m);
-		if (ret != 0) {
+		if (ret) {
 			dev_err(codec->dev, "First PLL write failed: %d\n", ret);
-			kfree(img_swap);
-			kfree(out);
-			goto abort;
+			goto abort_swap;
 		}
 
 		/* Use a second send of the message to get the return status */
 		ret = spi_sync(spi, &m);
-		if (ret != 0) {
+		if (ret) {
 			dev_err(codec->dev, "Second PLL write failed: %d\n", ret);
-			kfree(img_swap);
-			kfree(out);
-			goto abort;
+			goto abort_swap;
 		}
 
 		p = (u32 *)out;
@@ -727,6 +721,10 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 
 	return 0;
 
+abort_swap:
+	kfree(img_swap);
+abort_out:
+	kfree(out);
 abort:
 	/* Put the chip back into reset */
 	wm0010_halt(codec);
Signature · 1 line
1.9.1
maintainer
#6 lore raw

Applied "ASoC: wm0010: fix error path" to the asoc tree

In reply to Sudip Mukherjee

The patch

ASoC: wm0010: fix error path

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From f072f91aa7517386344476813ca0799e08fd0c35 Mon Sep 17 00:00:00 2001

From: Sudip Mukherjee <[email protected]>
Date: Fri, 18 Sep 2015 16:02:21 +0530
Subject: [PATCH] ASoC: wm0010: fix error path

Fix the error path so that we can free the allocated memory on the error path instead of releasing them individually on each error.

---
 sound/soc/codecs/wm0010.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
sound/soc/codecs/wm0010.c +10 -12
index 7a1bc40..76b2f88 100644
@@ -663,10 +663,8 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 		}
 
 		img_swap = kzalloc(len, GFP_KERNEL | GFP_DMA);
-		if (!img_swap) {
-			kfree(out);
-			goto abort;
-		}
+		if (!img_swap)
+			goto abort_out;
 
 		/* We need to re-order for 0010 */
 		byte_swap_64((u64 *)&pll_rec, img_swap, len);
@@ -681,20 +679,16 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 		spi_message_add_tail(&t, &m);
 
 		ret = spi_sync(spi, &m);
-		if (ret != 0) {
+		if (ret) {
 			dev_err(codec->dev, "First PLL write failed: %d\n", ret);
-			kfree(img_swap);
-			kfree(out);
-			goto abort;
+			goto abort_swap;
 		}
 
 		/* Use a second send of the message to get the return status */
 		ret = spi_sync(spi, &m);
-		if (ret != 0) {
+		if (ret) {
 			dev_err(codec->dev, "Second PLL write failed: %d\n", ret);
-			kfree(img_swap);
-			kfree(out);
-			goto abort;
+			goto abort_swap;
 		}
 
 		p = (u32 *)out;
@@ -727,6 +721,10 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 
 	return 0;
 
+abort_swap:
+	kfree(img_swap);
+abort_out:
+	kfree(out);
 abort:
 	/* Put the chip back into reset */
 	wm0010_halt(codec);
Signature · 1 line
2.5.0
#7 lore raw
In reply to Sudip Mukherjee
Quoted 13 lines · Sudip Mukherjee

We have done regulator_bulk_enable() while booting the DSP but on the error exit path we have not disbled it.

---
 sound/soc/codecs/wm0010.c | 2 --
 1 file changed, 2 deletions(-)
sound/soc/codecs/wm0010.c +0 -0
index 8434d45..79a7cd3 100644

sound/soc/codecs/wm0010.c static int wm0010_boot(struct snd_soc_codec *codec) · line 743

Quoted 5 lines
sound/soc/codecs/wm0010.c +0 -2
@@ -739,8 +739,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 abort:
 	/* Put the chip back into reset */
 	wm0010_halt(codec);
-	mutex_unlock(&wm0010->lock);
-	return ret;

Does wm0010_halt not disable the regulators?

Thanks,
Charles

Quoted 5 lines
sound/soc/codecs/wm0010.c +0 -0
 err_core:
 	mutex_unlock(&wm0010->lock);
Signature · 1 line
1.9.1
#8 lore raw
Quoted 9 lines · Charles Keepax
Quoted 8 lines · Sudip Mukherjee

We have done regulator_bulk_enable() while booting the DSP but on the error exit path we have not disbled it.

---
 sound/soc/codecs/wm0010.c | 2 --
 1 file changed, 2 deletions(-)
Quoted 12 lines

sound/soc/codecs/wm0010.c static int wm0010_boot(struct snd_soc_codec *codec) · line 743

Quoted 10 lines
sound/soc/codecs/wm0010.c +0 -2
index 8434d45..79a7cd3 100644
@@ -739,8 +739,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 abort:
 	/* Put the chip back into reset */
 	wm0010_halt(codec);
-	mutex_unlock(&wm0010->lock);
-	return ret;

Does wm0010_halt not disable the regulators?

oops, yes, it does. Sorry I should have seen it before posting. patch 2/3 and 3/3 will still apply even if this 1/3 is not applied. Should I send a v2 leaving out this patch or is it ok to discard this patch while applying?

regards
sudip

#9 lore raw
Quoted 22 lines · Sudip Mukherjee
Quoted 9 lines · Charles Keepax
Quoted 8 lines · Sudip Mukherjee

We have done regulator_bulk_enable() while booting the DSP but on the error exit path we have not disbled it.

---
 sound/soc/codecs/wm0010.c | 2 --
 1 file changed, 2 deletions(-)
Quoted 12 lines

sound/soc/codecs/wm0010.c static int wm0010_boot(struct snd_soc_codec *codec) · line 743

Quoted 10 lines
sound/soc/codecs/wm0010.c +0 -2
index 8434d45..79a7cd3 100644
@@ -739,8 +739,6 @@ static int wm0010_boot(struct snd_soc_codec *codec)
 abort:
 	/* Put the chip back into reset */
 	wm0010_halt(codec);
-	mutex_unlock(&wm0010->lock);
-	return ret;

Does wm0010_halt not disable the regulators?

Quoted 4 lines

oops, yes, it does. Sorry I should have seen it before posting. patch 2/3 and 3/3 will still apply even if this 1/3 is not applied. Should I send a v2 leaving out this patch or is it ok to discard this patch while applying?

As long as they apply cleanly I would think its fine to just leave them as is.

Thanks,
Charles