linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()'
@ 2021-08-20 18:43 Christophe JAILLET
  2021-10-29 20:07 ` Wolfram Sang
  2022-02-07 14:47 ` Wolfram Sang
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-08-20 18:43 UTC (permalink / raw)
  To: f.fainelli, rjui, sbranden, nsaenz, wsa, krzk, stefan.wahren, nh6z, eric
  Cc: linux-i2c, linux-rpi-kernel, linux-arm-kernel, linux-kernel,
	kernel-janitors, Christophe JAILLET

Some resource should be released if an error occurs in
'bcm2835_i2c_probe()'.
Add an error handling path and the needed 'clk_disable_unprepare()' and
'clk_rate_exclusive_put()' calls.

While at it, rework the bottom of the function to use this newly added
error handling path and have an explicit and more standard "return 0;" at
the end of the normal path.

Fixes: bebff81fb8b9 ("i2c: bcm2835: Model Divider in CCF")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/i2c/busses/i2c-bcm2835.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
index 37443edbf754..a2f19b4c2402 100644
--- a/drivers/i2c/busses/i2c-bcm2835.c
+++ b/drivers/i2c/busses/i2c-bcm2835.c
@@ -449,13 +449,14 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(i2c_dev->bus_clk);
 	if (ret) {
 		dev_err(&pdev->dev, "Couldn't prepare clock");
-		return ret;
+		goto err_put_exclusive_rate;
 	}
 
 	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (!irq) {
 		dev_err(&pdev->dev, "No IRQ resource\n");
-		return -ENODEV;
+		ret = -ENODEV;
+		goto err_disable_unprepare_clk;
 	}
 	i2c_dev->irq = irq->start;
 
@@ -463,7 +464,7 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
 			  dev_name(&pdev->dev), i2c_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "Could not request IRQ\n");
-		return -ENODEV;
+		goto err_disable_unprepare_clk;
 	}
 
 	adap = &i2c_dev->adapter;
@@ -481,7 +482,16 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
 
 	ret = i2c_add_adapter(adap);
 	if (ret)
-		free_irq(i2c_dev->irq, i2c_dev);
+		goto err_free_irq;
+
+	return 0;
+
+err_free_irq:
+	free_irq(i2c_dev->irq, i2c_dev);
+err_disable_unprepare_clk:
+	clk_disable_unprepare(i2c_dev->bus_clk);
+err_put_exclusive_rate:
+	clk_rate_exclusive_put(i2c_dev->bus_clk);
 
 	return ret;
 }
-- 
2.30.2


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

* Re: [PATCH] i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()'
  2021-08-20 18:43 [PATCH] i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()' Christophe JAILLET
@ 2021-10-29 20:07 ` Wolfram Sang
  2022-02-07 14:47 ` Wolfram Sang
  1 sibling, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2021-10-29 20:07 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: f.fainelli, rjui, sbranden, nsaenz, krzk, stefan.wahren, nh6z,
	eric, linux-i2c, linux-rpi-kernel, linux-arm-kernel,
	linux-kernel, kernel-janitors

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

On Fri, Aug 20, 2021 at 08:43:33PM +0200, Christophe JAILLET wrote:
> Some resource should be released if an error occurs in
> 'bcm2835_i2c_probe()'.
> Add an error handling path and the needed 'clk_disable_unprepare()' and
> 'clk_rate_exclusive_put()' calls.
> 
> While at it, rework the bottom of the function to use this newly added
> error handling path and have an explicit and more standard "return 0;" at
> the end of the normal path.
> 
> Fixes: bebff81fb8b9 ("i2c: bcm2835: Model Divider in CCF")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Could someone from the BCM community kindly test/approve this change?

> ---
>  drivers/i2c/busses/i2c-bcm2835.c | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
> index 37443edbf754..a2f19b4c2402 100644
> --- a/drivers/i2c/busses/i2c-bcm2835.c
> +++ b/drivers/i2c/busses/i2c-bcm2835.c
> @@ -449,13 +449,14 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
>  	ret = clk_prepare_enable(i2c_dev->bus_clk);
>  	if (ret) {
>  		dev_err(&pdev->dev, "Couldn't prepare clock");
> -		return ret;
> +		goto err_put_exclusive_rate;
>  	}
>  
>  	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>  	if (!irq) {
>  		dev_err(&pdev->dev, "No IRQ resource\n");
> -		return -ENODEV;
> +		ret = -ENODEV;
> +		goto err_disable_unprepare_clk;
>  	}
>  	i2c_dev->irq = irq->start;
>  
> @@ -463,7 +464,7 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
>  			  dev_name(&pdev->dev), i2c_dev);
>  	if (ret) {
>  		dev_err(&pdev->dev, "Could not request IRQ\n");
> -		return -ENODEV;
> +		goto err_disable_unprepare_clk;
>  	}
>  
>  	adap = &i2c_dev->adapter;
> @@ -481,7 +482,16 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
>  
>  	ret = i2c_add_adapter(adap);
>  	if (ret)
> -		free_irq(i2c_dev->irq, i2c_dev);
> +		goto err_free_irq;
> +
> +	return 0;
> +
> +err_free_irq:
> +	free_irq(i2c_dev->irq, i2c_dev);
> +err_disable_unprepare_clk:
> +	clk_disable_unprepare(i2c_dev->bus_clk);
> +err_put_exclusive_rate:
> +	clk_rate_exclusive_put(i2c_dev->bus_clk);
>  
>  	return ret;
>  }
> -- 
> 2.30.2
> 

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

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

* Re: [PATCH] i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()'
  2021-08-20 18:43 [PATCH] i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()' Christophe JAILLET
  2021-10-29 20:07 ` Wolfram Sang
@ 2022-02-07 14:47 ` Wolfram Sang
  2022-02-10 19:50   ` Christophe JAILLET
  1 sibling, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2022-02-07 14:47 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: f.fainelli, rjui, sbranden, nsaenz, krzk, stefan.wahren, nh6z,
	eric, linux-i2c, linux-rpi-kernel, linux-arm-kernel,
	linux-kernel, kernel-janitors

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

On Fri, Aug 20, 2021 at 08:43:33PM +0200, Christophe JAILLET wrote:
> Some resource should be released if an error occurs in
> 'bcm2835_i2c_probe()'.
> Add an error handling path and the needed 'clk_disable_unprepare()' and
> 'clk_rate_exclusive_put()' calls.
> 
> While at it, rework the bottom of the function to use this newly added
> error handling path and have an explicit and more standard "return 0;" at
> the end of the normal path.
> 
> Fixes: bebff81fb8b9 ("i2c: bcm2835: Model Divider in CCF")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Sadly, noone tested it but I think it is good to avoid the resource
leaks. So, rebased and applied to for-next, thanks! Please kindly check
if I rebased correctly the irq error case (once I pushed out).


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

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

* Re: [PATCH] i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()'
  2022-02-07 14:47 ` Wolfram Sang
@ 2022-02-10 19:50   ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2022-02-10 19:50 UTC (permalink / raw)
  To: Wolfram Sang, f.fainelli, rjui, sbranden, nsaenz, krzk,
	stefan.wahren, nh6z, eric, linux-i2c, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, kernel-janitors

Le 07/02/2022 à 15:47, Wolfram Sang a écrit :
> On Fri, Aug 20, 2021 at 08:43:33PM +0200, Christophe JAILLET wrote:
>> Some resource should be released if an error occurs in
>> 'bcm2835_i2c_probe()'.
>> Add an error handling path and the needed 'clk_disable_unprepare()' and
>> 'clk_rate_exclusive_put()' calls.
>>
>> While at it, rework the bottom of the function to use this newly added
>> error handling path and have an explicit and more standard "return 0;" at
>> the end of the normal path.
>>
>> Fixes: bebff81fb8b9 ("i2c: bcm2835: Model Divider in CCF")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> Sadly, noone tested it but I think it is good to avoid the resource
> leaks. So, rebased and applied to for-next, thanks! Please kindly check
> if I rebased correctly the irq error case (once I pushed out).
> 

LGTM.

CJ
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


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

end of thread, other threads:[~2022-02-10 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 18:43 [PATCH] i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()' Christophe JAILLET
2021-10-29 20:07 ` Wolfram Sang
2022-02-07 14:47 ` Wolfram Sang
2022-02-10 19:50   ` Christophe JAILLET

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