linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: tegra: Convert to managed resources
@ 2015-08-13  7:29 Vaishali Thakkar
  2015-08-17  7:17 ` Alexandre Courbot
  0 siblings, 1 reply; 8+ messages in thread
From: Vaishali Thakkar @ 2015-08-13  7:29 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Mark Brown, Jaroslav Kysela, Takashi Iwai, Stephen Warren,
	Thierry Reding, Alexandre Courbot, Wolfram Sang,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Use managed resource functions devm_clk_put and
devm_snd_soc_register_component to simplify error handling.

To be compatible with the change various gotos are replaced
with direct returns, and unneeded labels are dropped.

Signed-off-by: Vaishali Thakkar <vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 sound/soc/tegra/tegra20_spdif.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
index 9141477..f69b2e4 100644
--- a/sound/soc/tegra/tegra20_spdif.c
+++ b/sound/soc/tegra/tegra20_spdif.c
@@ -273,45 +273,40 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
 			     GFP_KERNEL);
 	if (!spdif) {
 		dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n");
-		ret = -ENOMEM;
-		goto err;
+		return -ENOMEM;
 	}
 	dev_set_drvdata(&pdev->dev, spdif);
 
-	spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
+	spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "spdif_out");
 	if (IS_ERR(spdif->clk_spdif_out)) {
 		pr_err("Can't retrieve spdif clock\n");
 		ret = PTR_ERR(spdif->clk_spdif_out);
-		goto err;
+		return ret;
 	}
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!mem) {
 		dev_err(&pdev->dev, "No memory resource\n");
-		ret = -ENODEV;
-		goto err_clk_put;
+		return -ENODEV;
 	}
 
 	dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
 	if (!dmareq) {
 		dev_err(&pdev->dev, "No DMA resource\n");
-		ret = -ENODEV;
-		goto err_clk_put;
+		return -ENODEV;
 	}
 
 	memregion = devm_request_mem_region(&pdev->dev, mem->start,
 					    resource_size(mem), DRV_NAME);
 	if (!memregion) {
 		dev_err(&pdev->dev, "Memory region already claimed\n");
-		ret = -EBUSY;
-		goto err_clk_put;
+		return -EBUSY;
 	}
 
 	regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
 	if (!regs) {
 		dev_err(&pdev->dev, "ioremap failed\n");
-		ret = -ENOMEM;
-		goto err_clk_put;
+		return -ENOMEM;
 	}
 
 	spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
@@ -319,7 +314,7 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
 	if (IS_ERR(spdif->regmap)) {
 		dev_err(&pdev->dev, "regmap init failed\n");
 		ret = PTR_ERR(spdif->regmap);
-		goto err_clk_put;
+		return ret;
 	}
 
 	spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT;
@@ -334,8 +329,9 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
 			goto err_pm_disable;
 	}
 
-	ret = snd_soc_register_component(&pdev->dev, &tegra20_spdif_component,
-				   &tegra20_spdif_dai, 1);
+	ret = devm_snd_soc_register_component(&pdev->dev,
+					      &tegra20_spdif_component,
+					      &tegra20_spdif_dai, 1);
 	if (ret) {
 		dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
 		ret = -ENOMEM;
@@ -345,21 +341,17 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
 	ret = tegra_pcm_platform_register(&pdev->dev);
 	if (ret) {
 		dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
-		goto err_unregister_component;
+		return ret;
 	}
 
 	return 0;
 
-err_unregister_component:
-	snd_soc_unregister_component(&pdev->dev);
 err_suspend:
 	if (!pm_runtime_status_suspended(&pdev->dev))
 		tegra20_spdif_runtime_suspend(&pdev->dev);
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
-err_clk_put:
-	clk_put(spdif->clk_spdif_out);
-err:
+
 	return ret;
 }
 
@@ -372,9 +364,6 @@ static int tegra20_spdif_platform_remove(struct platform_device *pdev)
 		tegra20_spdif_runtime_suspend(&pdev->dev);
 
 	tegra_pcm_platform_unregister(&pdev->dev);
-	snd_soc_unregister_component(&pdev->dev);
-
-	clk_put(spdif->clk_spdif_out);
 
 	return 0;
 }
-- 
1.9.1

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

* Re: [PATCH] ASoC: tegra: Convert to managed resources
  2015-08-13  7:29 [PATCH] ASoC: tegra: Convert to managed resources Vaishali Thakkar
@ 2015-08-17  7:17 ` Alexandre Courbot
       [not found]   ` <CAAVeFuKT1st8E1fxcDM5CV_OzUcTmvFw8UuU5oh15J1PiFJ0vA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Alexandre Courbot @ 2015-08-17  7:17 UTC (permalink / raw)
  To: Vaishali Thakkar
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Stephen Warren, Thierry Reding, Wolfram Sang,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux Kernel Mailing List

On Thu, Aug 13, 2015 at 4:29 PM, Vaishali Thakkar
<vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Use managed resource functions devm_clk_put and
> devm_snd_soc_register_component to simplify error handling.
>
> To be compatible with the change various gotos are replaced
> with direct returns, and unneeded labels are dropped.
>
> Signed-off-by: Vaishali Thakkar <vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  sound/soc/tegra/tegra20_spdif.c | 37 +++++++++++++------------------------
>  1 file changed, 13 insertions(+), 24 deletions(-)
>
> diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
> index 9141477..f69b2e4 100644
> --- a/sound/soc/tegra/tegra20_spdif.c
> +++ b/sound/soc/tegra/tegra20_spdif.c
> @@ -273,45 +273,40 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>                              GFP_KERNEL);
>         if (!spdif) {
>                 dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n");
> -               ret = -ENOMEM;
> -               goto err;
> +               return -ENOMEM;
>         }
>         dev_set_drvdata(&pdev->dev, spdif);
>
> -       spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
> +       spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "spdif_out");
>         if (IS_ERR(spdif->clk_spdif_out)) {
>                 pr_err("Can't retrieve spdif clock\n");
>                 ret = PTR_ERR(spdif->clk_spdif_out);
> -               goto err;
> +               return ret;

Maybe do "return PTR_ERR(spdif->clk_spdif_out);" for consistency with
the other error cases of this function?

>         }
>
>         mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>         if (!mem) {
>                 dev_err(&pdev->dev, "No memory resource\n");
> -               ret = -ENODEV;
> -               goto err_clk_put;
> +               return -ENODEV;
>         }
>
>         dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
>         if (!dmareq) {
>                 dev_err(&pdev->dev, "No DMA resource\n");
> -               ret = -ENODEV;
> -               goto err_clk_put;
> +               return -ENODEV;
>         }
>
>         memregion = devm_request_mem_region(&pdev->dev, mem->start,
>                                             resource_size(mem), DRV_NAME);
>         if (!memregion) {
>                 dev_err(&pdev->dev, "Memory region already claimed\n");
> -               ret = -EBUSY;
> -               goto err_clk_put;
> +               return -EBUSY;
>         }
>
>         regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
>         if (!regs) {
>                 dev_err(&pdev->dev, "ioremap failed\n");
> -               ret = -ENOMEM;
> -               goto err_clk_put;
> +               return -ENOMEM;
>         }
>
>         spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
> @@ -319,7 +314,7 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>         if (IS_ERR(spdif->regmap)) {
>                 dev_err(&pdev->dev, "regmap init failed\n");
>                 ret = PTR_ERR(spdif->regmap);
> -               goto err_clk_put;
> +               return ret;

Same here.

>         }
>
>         spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT;
> @@ -334,8 +329,9 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>                         goto err_pm_disable;
>         }
>
> -       ret = snd_soc_register_component(&pdev->dev, &tegra20_spdif_component,
> -                                  &tegra20_spdif_dai, 1);
> +       ret = devm_snd_soc_register_component(&pdev->dev,
> +                                             &tegra20_spdif_component,
> +                                             &tegra20_spdif_dai, 1);
>         if (ret) {
>                 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
>                 ret = -ENOMEM;
> @@ -345,21 +341,17 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>         ret = tegra_pcm_platform_register(&pdev->dev);
>         if (ret) {
>                 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
> -               goto err_unregister_component;
> +               return ret;

In the previous code, PM cleanup was also performed after the
component was unregistered. If you return directly, this is not
performed anymore - I think you should "goto err_suspend;" here.

This will change the ordering of cleanup operations though - e.g.
snd_soc_unregister_component() will now be called *after* PM cleanup.
Are things still working ok after this? (I suppose they do considering
how simple the PM ops are, but it might be worth testing).

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

* Re: [PATCH] ASoC: tegra: Convert to managed resources
       [not found]   ` <CAAVeFuKT1st8E1fxcDM5CV_OzUcTmvFw8UuU5oh15J1PiFJ0vA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2015-08-17  9:32     ` Vaishali Thakkar
  2015-08-17 20:47       ` Mark Brown
       [not found]       ` <CAK-LDbJwfuqU6ekRudms=YfjVxWf1BOREBwCnCh4v-YWY9hA_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Vaishali Thakkar @ 2015-08-17  9:32 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Stephen Warren, Thierry Reding, Wolfram Sang,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux Kernel Mailing List

On Mon, Aug 17, 2015 at 12:47 PM, Alexandre Courbot <gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> On Thu, Aug 13, 2015 at 4:29 PM, Vaishali Thakkar
> <vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> Use managed resource functions devm_clk_put and
>> devm_snd_soc_register_component to simplify error handling.
>>
>> To be compatible with the change various gotos are replaced
>> with direct returns, and unneeded labels are dropped.
>>
>> Signed-off-by: Vaishali Thakkar <vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> ---
>>  sound/soc/tegra/tegra20_spdif.c | 37 +++++++++++++------------------------
>>  1 file changed, 13 insertions(+), 24 deletions(-)
>>
>> diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
>> index 9141477..f69b2e4 100644
>> --- a/sound/soc/tegra/tegra20_spdif.c
>> +++ b/sound/soc/tegra/tegra20_spdif.c
>> @@ -273,45 +273,40 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>                              GFP_KERNEL);
>>         if (!spdif) {
>>                 dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n");
>> -               ret = -ENOMEM;
>> -               goto err;
>> +               return -ENOMEM;
>>         }
>>         dev_set_drvdata(&pdev->dev, spdif);
>>
>> -       spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
>> +       spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "spdif_out");
>>         if (IS_ERR(spdif->clk_spdif_out)) {
>>                 pr_err("Can't retrieve spdif clock\n");
>>                 ret = PTR_ERR(spdif->clk_spdif_out);
>> -               goto err;
>> +               return ret;
>
> Maybe do "return PTR_ERR(spdif->clk_spdif_out);" for consistency with
> the other error cases of this function?
>
>>         }
>>
>>         mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>         if (!mem) {
>>                 dev_err(&pdev->dev, "No memory resource\n");
>> -               ret = -ENODEV;
>> -               goto err_clk_put;
>> +               return -ENODEV;
>>         }
>>
>>         dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
>>         if (!dmareq) {
>>                 dev_err(&pdev->dev, "No DMA resource\n");
>> -               ret = -ENODEV;
>> -               goto err_clk_put;
>> +               return -ENODEV;
>>         }
>>
>>         memregion = devm_request_mem_region(&pdev->dev, mem->start,
>>                                             resource_size(mem), DRV_NAME);
>>         if (!memregion) {
>>                 dev_err(&pdev->dev, "Memory region already claimed\n");
>> -               ret = -EBUSY;
>> -               goto err_clk_put;
>> +               return -EBUSY;
>>         }
>>
>>         regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
>>         if (!regs) {
>>                 dev_err(&pdev->dev, "ioremap failed\n");
>> -               ret = -ENOMEM;
>> -               goto err_clk_put;
>> +               return -ENOMEM;
>>         }
>>
>>         spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
>> @@ -319,7 +314,7 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>         if (IS_ERR(spdif->regmap)) {
>>                 dev_err(&pdev->dev, "regmap init failed\n");
>>                 ret = PTR_ERR(spdif->regmap);
>> -               goto err_clk_put;
>> +               return ret;
>
> Same here.

Actually people prefer to write this way when they are calling PTR_ERR
more than one time for the same value. But as for this file at both places
we are calling PTR_ERR for different values, may be we can directly call
it in return.

>>         }
>>
>>         spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT;
>> @@ -334,8 +329,9 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>                         goto err_pm_disable;
>>         }
>>
>> -       ret = snd_soc_register_component(&pdev->dev, &tegra20_spdif_component,
>> -                                  &tegra20_spdif_dai, 1);
>> +       ret = devm_snd_soc_register_component(&pdev->dev,
>> +                                             &tegra20_spdif_component,
>> +                                             &tegra20_spdif_dai, 1);
>>         if (ret) {
>>                 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
>>                 ret = -ENOMEM;
>> @@ -345,21 +341,17 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>         ret = tegra_pcm_platform_register(&pdev->dev);
>>         if (ret) {
>>                 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
>> -               goto err_unregister_component;
>> +               return ret;
>
> In the previous code, PM cleanup was also performed after the
> component was unregistered. If you return directly, this is not
> performed anymore - I think you should "goto err_suspend;" here.
> This will change the ordering of cleanup operations though - e.g.
> snd_soc_unregister_component() will now be called *after* PM cleanup.
> Are things still working ok after this? (I suppose they do considering
> how simple the PM ops are, but it might be worth testing).

I think you are right. I missed that. But now thing is , this patch is already
applied here:
https://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/commit/?h=topic/tegra

I am not sure if now I can change version 2 with the changes you suggested
or not. Although I will not be able to test it  after changing 'goto
err_suspend'
as I don't have hardware but may be someone else can test it.

-- 
Vaishali

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

* Re: [PATCH] ASoC: tegra: Convert to managed resources
  2015-08-17  9:32     ` Vaishali Thakkar
@ 2015-08-17 20:47       ` Mark Brown
       [not found]         ` <20150817204751.GD10748-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
       [not found]       ` <CAK-LDbJwfuqU6ekRudms=YfjVxWf1BOREBwCnCh4v-YWY9hA_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Mark Brown @ 2015-08-17 20:47 UTC (permalink / raw)
  To: Vaishali Thakkar
  Cc: Alexandre Courbot, alsa-devel@alsa-project.org, Stephen Warren,
	Linux Kernel Mailing List, Wolfram Sang, Takashi Iwai,
	Liam Girdwood, Thierry Reding, linux-tegra@vger.kernel.org


[-- Attachment #1.1: Type: text/plain, Size: 720 bytes --]

On Mon, Aug 17, 2015 at 03:02:29PM +0530, Vaishali Thakkar wrote:

> I think you are right. I missed that. But now thing is , this patch is already
> applied here:
> https://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/commit/?h=topic/tegra

> I am not sure if now I can change version 2 with the changes you suggested
> or not. Although I will not be able to test it  after changing 'goto
> err_suspend'
> as I don't have hardware but may be someone else can test it.

You can send an incremental update on top of what's there, or it may be
more sensible to just discard the change entirely.  I suspect we're safe
with either PM vs component ordering though since we should support !PM
configurations anyway.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

* Re: [PATCH] ASoC: tegra: Convert to managed resources
       [not found]         ` <20150817204751.GD10748-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2015-08-18  2:45           ` Vaishali Thakkar
       [not found]             ` <CAK-LDbLCvdUiNZ17oxWwuUhC=hwtpuGeYdxXj=0Y3q48gkbzRw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Vaishali Thakkar @ 2015-08-18  2:45 UTC (permalink / raw)
  To: Mark Brown
  Cc: Alexandre Courbot, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Stephen Warren, Thierry Reding, Wolfram Sang,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux Kernel Mailing List

On Tue, Aug 18, 2015 at 2:17 AM, Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> On Mon, Aug 17, 2015 at 03:02:29PM +0530, Vaishali Thakkar wrote:
>
>> I think you are right. I missed that. But now thing is , this patch is already
>> applied here:
>> https://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/commit/?h=topic/tegra
>
>> I am not sure if now I can change version 2 with the changes you suggested
>> or not. Although I will not be able to test it  after changing 'goto
>> err_suspend'
>> as I don't have hardware but may be someone else can test it.
>
> You can send an incremental update on top of what's there, or it may be
> more sensible to just discard the change entirely.  I suspect we're safe
> with either PM vs component ordering though since we should support !PM
> configurations anyway.

I think yes may be code was good before this. But devm_clk_put part should work
fine as call of it is before PM stuff. So, can I send a patch
reverting the change
of component part or do you want me to send a patch reverting whole change?


-- 
Vaishali

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

* Re: [PATCH] ASoC: tegra: Convert to managed resources
       [not found]             ` <CAK-LDbLCvdUiNZ17oxWwuUhC=hwtpuGeYdxXj=0Y3q48gkbzRw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2015-08-18  5:15               ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2015-08-18  5:15 UTC (permalink / raw)
  To: Vaishali Thakkar
  Cc: Alexandre Courbot, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Stephen Warren, Thierry Reding, Wolfram Sang,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux Kernel Mailing List

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

On Tue, Aug 18, 2015 at 08:15:35AM +0530, Vaishali Thakkar wrote:

> I think yes may be code was good before this. But devm_clk_put part should work
> fine as call of it is before PM stuff. So, can I send a patch
> reverting the change
> of component part or do you want me to send a patch reverting whole change?

Just fixing the problematic part is fine.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [PATCH] ASoC: tegra: Convert to managed resources
       [not found]       ` <CAK-LDbJwfuqU6ekRudms=YfjVxWf1BOREBwCnCh4v-YWY9hA_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2015-08-18  7:18         ` Alexandre Courbot
  2015-08-18 11:56           ` Vaishali Thakkar
  0 siblings, 1 reply; 8+ messages in thread
From: Alexandre Courbot @ 2015-08-18  7:18 UTC (permalink / raw)
  To: Vaishali Thakkar
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Stephen Warren, Thierry Reding, Wolfram Sang,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux Kernel Mailing List

On Mon, Aug 17, 2015 at 6:32 PM, Vaishali Thakkar
<vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> On Mon, Aug 17, 2015 at 12:47 PM, Alexandre Courbot <gnurou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> On Thu, Aug 13, 2015 at 4:29 PM, Vaishali Thakkar
>> <vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>> Use managed resource functions devm_clk_put and
>>> devm_snd_soc_register_component to simplify error handling.
>>>
>>> To be compatible with the change various gotos are replaced
>>> with direct returns, and unneeded labels are dropped.
>>>
>>> Signed-off-by: Vaishali Thakkar <vthakkar1994-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>>> ---
>>>  sound/soc/tegra/tegra20_spdif.c | 37 +++++++++++++------------------------
>>>  1 file changed, 13 insertions(+), 24 deletions(-)
>>>
>>> diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
>>> index 9141477..f69b2e4 100644
>>> --- a/sound/soc/tegra/tegra20_spdif.c
>>> +++ b/sound/soc/tegra/tegra20_spdif.c
>>> @@ -273,45 +273,40 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>                              GFP_KERNEL);
>>>         if (!spdif) {
>>>                 dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n");
>>> -               ret = -ENOMEM;
>>> -               goto err;
>>> +               return -ENOMEM;
>>>         }
>>>         dev_set_drvdata(&pdev->dev, spdif);
>>>
>>> -       spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
>>> +       spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "spdif_out");
>>>         if (IS_ERR(spdif->clk_spdif_out)) {
>>>                 pr_err("Can't retrieve spdif clock\n");
>>>                 ret = PTR_ERR(spdif->clk_spdif_out);
>>> -               goto err;
>>> +               return ret;
>>
>> Maybe do "return PTR_ERR(spdif->clk_spdif_out);" for consistency with
>> the other error cases of this function?
>>
>>>         }
>>>
>>>         mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>>         if (!mem) {
>>>                 dev_err(&pdev->dev, "No memory resource\n");
>>> -               ret = -ENODEV;
>>> -               goto err_clk_put;
>>> +               return -ENODEV;
>>>         }
>>>
>>>         dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
>>>         if (!dmareq) {
>>>                 dev_err(&pdev->dev, "No DMA resource\n");
>>> -               ret = -ENODEV;
>>> -               goto err_clk_put;
>>> +               return -ENODEV;
>>>         }
>>>
>>>         memregion = devm_request_mem_region(&pdev->dev, mem->start,
>>>                                             resource_size(mem), DRV_NAME);
>>>         if (!memregion) {
>>>                 dev_err(&pdev->dev, "Memory region already claimed\n");
>>> -               ret = -EBUSY;
>>> -               goto err_clk_put;
>>> +               return -EBUSY;
>>>         }
>>>
>>>         regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
>>>         if (!regs) {
>>>                 dev_err(&pdev->dev, "ioremap failed\n");
>>> -               ret = -ENOMEM;
>>> -               goto err_clk_put;
>>> +               return -ENOMEM;
>>>         }
>>>
>>>         spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
>>> @@ -319,7 +314,7 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>         if (IS_ERR(spdif->regmap)) {
>>>                 dev_err(&pdev->dev, "regmap init failed\n");
>>>                 ret = PTR_ERR(spdif->regmap);
>>> -               goto err_clk_put;
>>> +               return ret;
>>
>> Same here.
>
> Actually people prefer to write this way when they are calling PTR_ERR
> more than one time for the same value. But as for this file at both places
> we are calling PTR_ERR for different values, may be we can directly call
> it in return.

Ok, I don't feel too strongly about this, so your call.

>
>>>         }
>>>
>>>         spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT;
>>> @@ -334,8 +329,9 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>                         goto err_pm_disable;
>>>         }
>>>
>>> -       ret = snd_soc_register_component(&pdev->dev, &tegra20_spdif_component,
>>> -                                  &tegra20_spdif_dai, 1);
>>> +       ret = devm_snd_soc_register_component(&pdev->dev,
>>> +                                             &tegra20_spdif_component,
>>> +                                             &tegra20_spdif_dai, 1);
>>>         if (ret) {
>>>                 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
>>>                 ret = -ENOMEM;
>>> @@ -345,21 +341,17 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>         ret = tegra_pcm_platform_register(&pdev->dev);
>>>         if (ret) {
>>>                 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
>>> -               goto err_unregister_component;
>>> +               return ret;
>>
>> In the previous code, PM cleanup was also performed after the
>> component was unregistered. If you return directly, this is not
>> performed anymore - I think you should "goto err_suspend;" here.
>> This will change the ordering of cleanup operations though - e.g.
>> snd_soc_unregister_component() will now be called *after* PM cleanup.
>> Are things still working ok after this? (I suppose they do considering
>> how simple the PM ops are, but it might be worth testing).
>
> I think you are right. I missed that. But now thing is , this patch is already
> applied here:
> https://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/commit/?h=topic/tegra

Ah, that will teach me to check my patches queue more often. :(

>
> I am not sure if now I can change version 2 with the changes you suggested
> or not. Although I will not be able to test it  after changing 'goto
> err_suspend'
> as I don't have hardware but may be someone else can test it.

I think you can send a fixup patch since Mark already merged this one,
this is an error code path (which by definition should not be taken
too often), and there should not be any resulting breakage.

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

* Re: [PATCH] ASoC: tegra: Convert to managed resources
  2015-08-18  7:18         ` Alexandre Courbot
@ 2015-08-18 11:56           ` Vaishali Thakkar
  0 siblings, 0 replies; 8+ messages in thread
From: Vaishali Thakkar @ 2015-08-18 11:56 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Stephen Warren, Thierry Reding, Wolfram Sang,
	alsa-devel@alsa-project.org, linux-tegra@vger.kernel.org,
	Linux Kernel Mailing List

On Tue, Aug 18, 2015 at 12:48 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
> On Mon, Aug 17, 2015 at 6:32 PM, Vaishali Thakkar
> <vthakkar1994@gmail.com> wrote:
>> On Mon, Aug 17, 2015 at 12:47 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
>>> On Thu, Aug 13, 2015 at 4:29 PM, Vaishali Thakkar
>>> <vthakkar1994@gmail.com> wrote:
>>>> Use managed resource functions devm_clk_put and
>>>> devm_snd_soc_register_component to simplify error handling.
>>>>
>>>> To be compatible with the change various gotos are replaced
>>>> with direct returns, and unneeded labels are dropped.
>>>>
>>>> Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
>>>> ---
>>>>  sound/soc/tegra/tegra20_spdif.c | 37 +++++++++++++------------------------
>>>>  1 file changed, 13 insertions(+), 24 deletions(-)
>>>>
>>>> diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
>>>> index 9141477..f69b2e4 100644
>>>> --- a/sound/soc/tegra/tegra20_spdif.c
>>>> +++ b/sound/soc/tegra/tegra20_spdif.c
>>>> @@ -273,45 +273,40 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>>                              GFP_KERNEL);
>>>>         if (!spdif) {
>>>>                 dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n");
>>>> -               ret = -ENOMEM;
>>>> -               goto err;
>>>> +               return -ENOMEM;
>>>>         }
>>>>         dev_set_drvdata(&pdev->dev, spdif);
>>>>
>>>> -       spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
>>>> +       spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "spdif_out");
>>>>         if (IS_ERR(spdif->clk_spdif_out)) {
>>>>                 pr_err("Can't retrieve spdif clock\n");
>>>>                 ret = PTR_ERR(spdif->clk_spdif_out);
>>>> -               goto err;
>>>> +               return ret;
>>>
>>> Maybe do "return PTR_ERR(spdif->clk_spdif_out);" for consistency with
>>> the other error cases of this function?
>>>
>>>>         }
>>>>
>>>>         mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>>>         if (!mem) {
>>>>                 dev_err(&pdev->dev, "No memory resource\n");
>>>> -               ret = -ENODEV;
>>>> -               goto err_clk_put;
>>>> +               return -ENODEV;
>>>>         }
>>>>
>>>>         dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
>>>>         if (!dmareq) {
>>>>                 dev_err(&pdev->dev, "No DMA resource\n");
>>>> -               ret = -ENODEV;
>>>> -               goto err_clk_put;
>>>> +               return -ENODEV;
>>>>         }
>>>>
>>>>         memregion = devm_request_mem_region(&pdev->dev, mem->start,
>>>>                                             resource_size(mem), DRV_NAME);
>>>>         if (!memregion) {
>>>>                 dev_err(&pdev->dev, "Memory region already claimed\n");
>>>> -               ret = -EBUSY;
>>>> -               goto err_clk_put;
>>>> +               return -EBUSY;
>>>>         }
>>>>
>>>>         regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
>>>>         if (!regs) {
>>>>                 dev_err(&pdev->dev, "ioremap failed\n");
>>>> -               ret = -ENOMEM;
>>>> -               goto err_clk_put;
>>>> +               return -ENOMEM;
>>>>         }
>>>>
>>>>         spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
>>>> @@ -319,7 +314,7 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>>         if (IS_ERR(spdif->regmap)) {
>>>>                 dev_err(&pdev->dev, "regmap init failed\n");
>>>>                 ret = PTR_ERR(spdif->regmap);
>>>> -               goto err_clk_put;
>>>> +               return ret;
>>>
>>> Same here.
>>
>> Actually people prefer to write this way when they are calling PTR_ERR
>> more than one time for the same value. But as for this file at both places
>> we are calling PTR_ERR for different values, may be we can directly call
>> it in return.
>
> Ok, I don't feel too strongly about this, so your call.
>
>>
>>>>         }
>>>>
>>>>         spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT;
>>>> @@ -334,8 +329,9 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>>                         goto err_pm_disable;
>>>>         }
>>>>
>>>> -       ret = snd_soc_register_component(&pdev->dev, &tegra20_spdif_component,
>>>> -                                  &tegra20_spdif_dai, 1);
>>>> +       ret = devm_snd_soc_register_component(&pdev->dev,
>>>> +                                             &tegra20_spdif_component,
>>>> +                                             &tegra20_spdif_dai, 1);
>>>>         if (ret) {
>>>>                 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
>>>>                 ret = -ENOMEM;
>>>> @@ -345,21 +341,17 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
>>>>         ret = tegra_pcm_platform_register(&pdev->dev);
>>>>         if (ret) {
>>>>                 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
>>>> -               goto err_unregister_component;
>>>> +               return ret;
>>>
>>> In the previous code, PM cleanup was also performed after the
>>> component was unregistered. If you return directly, this is not
>>> performed anymore - I think you should "goto err_suspend;" here.
>>> This will change the ordering of cleanup operations though - e.g.
>>> snd_soc_unregister_component() will now be called *after* PM cleanup.
>>> Are things still working ok after this? (I suppose they do considering
>>> how simple the PM ops are, but it might be worth testing).
>>
>> I think you are right. I missed that. But now thing is , this patch is already
>> applied here:
>> https://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/commit/?h=topic/tegra
>
> Ah, that will teach me to check my patches queue more often. :(
>
>>
>> I am not sure if now I can change version 2 with the changes you suggested
>> or not. Although I will not be able to test it  after changing 'goto
>> err_suspend'
>> as I don't have hardware but may be someone else can test it.
>
> I think you can send a fixup patch since Mark already merged this one,
> this is an error code path (which by definition should not be taken
> too often), and there should not be any resulting breakage.

Yes. As per the discussion with Mark, I am sending a patch reverting
the change of component part.

Thanks for your review.

-- 
Vaishali

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

end of thread, other threads:[~2015-08-18 11:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-13  7:29 [PATCH] ASoC: tegra: Convert to managed resources Vaishali Thakkar
2015-08-17  7:17 ` Alexandre Courbot
     [not found]   ` <CAAVeFuKT1st8E1fxcDM5CV_OzUcTmvFw8UuU5oh15J1PiFJ0vA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-17  9:32     ` Vaishali Thakkar
2015-08-17 20:47       ` Mark Brown
     [not found]         ` <20150817204751.GD10748-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-18  2:45           ` Vaishali Thakkar
     [not found]             ` <CAK-LDbLCvdUiNZ17oxWwuUhC=hwtpuGeYdxXj=0Y3q48gkbzRw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-18  5:15               ` Mark Brown
     [not found]       ` <CAK-LDbJwfuqU6ekRudms=YfjVxWf1BOREBwCnCh4v-YWY9hA_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-18  7:18         ` Alexandre Courbot
2015-08-18 11:56           ` Vaishali Thakkar

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).