Fix error handling in pcm030_fabric_probe

[PATCH] ASoC: fsl: Fix error handling in pcm030_fabric_probe

* [PATCH] ASoC: fsl: Fix error handling in pcm030_fabric_probe
@ 2022-03-01  7:53 Miaoqian Lin
  2022-03-02 13:44 ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Miaoqian Lin @ 2022-03-01  7:53 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Miaoqian Lin, alsa-devel, linux-kernel

This will call twice platform_device_put()
if both platform_device_add() and snd_soc_register_card() fails.
Fix it by using goto label to avoid duplicating the error code logic.

Fixes: fb25621da570 ("ASoC: fsl: Add missing error handling in pcm030_fabric_probe")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 sound/soc/fsl/pcm030-audio-fabric.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c
index 83b4a22bf15a..d397bb97f37b 100644
--- a/sound/soc/fsl/pcm030-audio-fabric.c
+++ b/sound/soc/fsl/pcm030-audio-fabric.c
@@ -95,19 +95,23 @@ static int pcm030_fabric_probe(struct platform_device *op)
 	ret = platform_device_add(pdata->codec_device);
 	if (ret) {
 		dev_err(&op->dev, "platform_device_add() failed: %d\n", ret);
-		platform_device_put(pdata->codec_device);
+		goto err_add;
 	}
 
 	ret = snd_soc_register_card(card);
 	if (ret) {
 		dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret);
-		platform_device_del(pdata->codec_device);
-		platform_device_put(pdata->codec_device);
+		goto err_register;
 	}
 
 	platform_set_drvdata(op, pdata);
 	return ret;
 
+err_register:
+	platform_device_del(pdata->codec_device);
+err_add:
+	platform_device_put(pdata->codec_device);
+	return ret;
 }
 
 static int pcm030_fabric_remove(struct platform_device *op)
-- 
2.17.1


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

* Re: [PATCH] ASoC: fsl: Fix error handling in pcm030_fabric_probe
  2022-03-01  7:53 [PATCH] ASoC: fsl: Fix error handling in pcm030_fabric_probe Miaoqian Lin
@ 2022-03-02 13:44 ` Mark Brown
  2022-04-20  2:18   ` [PATCH v2] " Miaoqian Lin
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2022-03-02 13:44 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

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

On Tue, Mar 01, 2022 at 07:53:48AM +0000, Miaoqian Lin wrote:
> This will call twice platform_device_put()
> if both platform_device_add() and snd_soc_register_card() fails.
> Fix it by using goto label to avoid duplicating the error code logic.

This doesn't apply against current code, please check and resend.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* [PATCH v2] ASoC: fsl: Fix error handling in pcm030_fabric_probe
  2022-03-02 13:44 ` Mark Brown
@ 2022-04-20  2:18   ` Miaoqian Lin
  2022-04-20 13:00     ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Miaoqian Lin @ 2022-04-20  2:18 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Miaoqian Lin, alsa-devel, linux-kernel

This will call twice platform_device_put()
if both platform_device_add() and snd_soc_register_card() fails.
return early on error  to avoid duplicating the error code logic.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- use return statement to return early when fails
- rebase on top of commit 559089e0a93d ("vmalloc: replace VM_NO_HUGE_VMAP with VM_ALLOW_HUGE_VMAP")
---
 sound/soc/fsl/pcm030-audio-fabric.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c
index 83b4a22bf15a..096a37993ad3 100644
--- a/sound/soc/fsl/pcm030-audio-fabric.c
+++ b/sound/soc/fsl/pcm030-audio-fabric.c
@@ -89,13 +89,16 @@ static int pcm030_fabric_probe(struct platform_device *op)
 		dev_err(&op->dev, "request_module returned: %d\n", ret);
 
 	pdata->codec_device = platform_device_alloc("wm9712-codec", -1);
-	if (!pdata->codec_device)
+	if (!pdata->codec_device) {
 		dev_err(&op->dev, "platform_device_alloc() failed\n");
+		return -ENOMEM;
+	}
 
 	ret = platform_device_add(pdata->codec_device);
 	if (ret) {
 		dev_err(&op->dev, "platform_device_add() failed: %d\n", ret);
 		platform_device_put(pdata->codec_device);
+		return ret;
 	}
 
 	ret = snd_soc_register_card(card);
@@ -103,6 +106,7 @@ static int pcm030_fabric_probe(struct platform_device *op)
 		dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret);
 		platform_device_del(pdata->codec_device);
 		platform_device_put(pdata->codec_device);
+		return ret;
 	}
 
 	platform_set_drvdata(op, pdata);
-- 
2.17.1


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

* Re: [PATCH v2] ASoC: fsl: Fix error handling in pcm030_fabric_probe
  2022-04-20  2:18   ` [PATCH v2] " Miaoqian Lin
@ 2022-04-20 13:00     ` Mark Brown
  2022-04-20 13:35       ` Miaoqian Lin
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2022-04-20 13:00 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

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

On Wed, Apr 20, 2022 at 02:18:52AM +0000, Miaoqian Lin wrote:
> This will call twice platform_device_put()
> if both platform_device_add() and snd_soc_register_card() fails.
> return early on error  to avoid duplicating the error code logic.
> 
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> changes in v2:
> - use return statement to return early when fails
> - rebase on top of commit 559089e0a93d ("vmalloc: replace VM_NO_HUGE_VMAP with VM_ALLOW_HUGE_VMAP")

Why rebase on top of that seemingly random commit?  Is there some sort
of dependency here?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2] ASoC: fsl: Fix error handling in pcm030_fabric_probe
  2022-04-20 13:00     ` Mark Brown
@ 2022-04-20 13:35       ` Miaoqian Lin
  2022-04-20 13:41         ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Miaoqian Lin @ 2022-04-20 13:35 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel


On 2022/4/20 21:00, Mark Brown wrote:
> On Wed, Apr 20, 2022 at 02:18:52AM +0000, Miaoqian Lin wrote:
>> This will call twice platform_device_put()
>> if both platform_device_add() and snd_soc_register_card() fails.
>> return early on error  to avoid duplicating the error code logic.
>>
>> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
>> ---
>> changes in v2:
>> - use return statement to return early when fails
>> - rebase on top of commit 559089e0a93d ("vmalloc: replace VM_NO_HUGE_VMAP with VM_ALLOW_HUGE_VMAP")
> Why rebase on top of that seemingly random commit?  Is there some sort
> of dependency here?

Hi, it the head of master in when I made this patch. It's because you pointed out

that patch v1 doesn't apply against current code. But I am not sure what's the problem.

So I ensure the codebase is up-to-date. If this patch have no conflict, you can ignore it.


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

* Re: [PATCH v2] ASoC: fsl: Fix error handling in pcm030_fabric_probe
  2022-04-20 13:35       ` Miaoqian Lin
@ 2022-04-20 13:41         ` Mark Brown
  2022-04-20 13:45           ` Miaoqian Lin
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2022-04-20 13:41 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel

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

On Wed, Apr 20, 2022 at 09:35:55PM +0800, Miaoqian Lin wrote:
> On 2022/4/20 21:00, Mark Brown wrote:

> >> - rebase on top of commit 559089e0a93d ("vmalloc: replace VM_NO_HUGE_VMAP with VM_ALLOW_HUGE_VMAP")

> > Why rebase on top of that seemingly random commit?  Is there some sort
> > of dependency here?

> Hi, it the head of master in when I made this patch. It's because you pointed out

> that patch v1 doesn't apply against current code. But I am not sure what's the problem.

> So I ensure the codebase is up-to-date. If this patch have no conflict, you can ignore it.

Current code here is my git tree (-next is often a fair approximation) -
if people have been making changes since the merge window then often
code written against mainline won't apply and things need to be based on
people's current work.  You're looking for

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2] ASoC: fsl: Fix error handling in pcm030_fabric_probe
  2022-04-20 13:41         ` Mark Brown
@ 2022-04-20 13:45           ` Miaoqian Lin
  0 siblings, 0 replies; 7+ messages in thread
From: Miaoqian Lin @ 2022-04-20 13:45 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel


On 2022/4/20 21:41, Mark Brown wrote:
> On Wed, Apr 20, 2022 at 09:35:55PM +0800, Miaoqian Lin wrote:
>> On 2022/4/20 21:00, Mark Brown wrote:
>>>> - rebase on top of commit 559089e0a93d ("vmalloc: replace VM_NO_HUGE_VMAP with VM_ALLOW_HUGE_VMAP")
>>> Why rebase on top of that seemingly random commit?  Is there some sort
>>> of dependency here?
>> Hi, it the head of master in when I made this patch. It's because you pointed out
>> that patch v1 doesn't apply against current code. But I am not sure what's the problem.
>> So I ensure the codebase is up-to-date. If this patch have no conflict, you can ignore it.
> Current code here is my git tree (-next is often a fair approximation) -
> if people have been making changes since the merge window then often
> code written against mainline won't apply and things need to be based on
> people's current work.  You're looking for
>
>    https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

I get it, thanks for your kindly reminder.


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

end of thread, other threads:[~2022-04-20 13:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01  7:53 [PATCH] ASoC: fsl: Fix error handling in pcm030_fabric_probe Miaoqian Lin
2022-03-02 13:44 ` Mark Brown
2022-04-20  2:18   ` [PATCH v2] " Miaoqian Lin
2022-04-20 13:00     ` Mark Brown
2022-04-20 13:35       ` Miaoqian Lin
2022-04-20 13:41         ` Mark Brown
2022-04-20 13:45           ` Miaoqian Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).

Read more here: Source link