linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] [media] mantis: Fix goto labels
@ 2015-02-15 12:11 Silvan Jegen
  2015-02-15 12:11 ` [PATCH 1/2] [media] mantis: Move jump label to activate dead code Silvan Jegen
  2015-02-15 12:11 ` [PATCH 2/2] [media] mantis: Use correct goto labels for cleanup on error Silvan Jegen
  0 siblings, 2 replies; 9+ messages in thread
From: Silvan Jegen @ 2015-02-15 12:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, linux-media
  Cc: Silvan Jegen, linux-kernel, kernel-janitors

I found two issues regarding goto labels in the mantis driver
when checking a smatch warning and addressed them in two separate
patches. Please be aware that these patches have only been compile-tested
since I do not have access to the corresponding hardware.

Silvan Jegen (2):
  [media] mantis: Move jump label to activate dead code
  [media] mantis: Use correct goto labels for cleanup on error

 drivers/media/pci/mantis/mantis_cards.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

-- 
2.2.2


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

* [PATCH 1/2] [media] mantis: Move jump label to activate dead code
  2015-02-15 12:11 [PATCH 0/2] [media] mantis: Fix goto labels Silvan Jegen
@ 2015-02-15 12:11 ` Silvan Jegen
  2015-02-16  9:04   ` Dan Carpenter
  2015-02-15 12:11 ` [PATCH 2/2] [media] mantis: Use correct goto labels for cleanup on error Silvan Jegen
  1 sibling, 1 reply; 9+ messages in thread
From: Silvan Jegen @ 2015-02-15 12:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, linux-media
  Cc: Silvan Jegen, linux-kernel, kernel-janitors

Due to a misplaced goto label mantis_uart_exit is never called.  Adjusting
the label position (while correcting its numbering) changes this.

This issue was found using the smatch static checker.

Signed-off-by: Silvan Jegen <s.jegen@gmail.com>
---
 drivers/media/pci/mantis/mantis_cards.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
index 801fc55..e566061 100644
--- a/drivers/media/pci/mantis/mantis_cards.c
+++ b/drivers/media/pci/mantis/mantis_cards.c
@@ -215,10 +215,11 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
 		goto fail4;
 	}
+
 	err = mantis_uart_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
-		goto fail6;
+		goto fail5;
 	}
 
 	devs++;
@@ -226,10 +227,10 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 	return err;
 
 
+fail5:
 	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);
 	mantis_uart_exit(mantis);
 
-fail6:
 fail4:
 	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
 	mantis_dma_exit(mantis);
-- 
2.2.2


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

* [PATCH 2/2] [media] mantis: Use correct goto labels for cleanup on error
  2015-02-15 12:11 [PATCH 0/2] [media] mantis: Fix goto labels Silvan Jegen
  2015-02-15 12:11 ` [PATCH 1/2] [media] mantis: Move jump label to activate dead code Silvan Jegen
@ 2015-02-15 12:11 ` Silvan Jegen
  1 sibling, 0 replies; 9+ messages in thread
From: Silvan Jegen @ 2015-02-15 12:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, linux-media
  Cc: Silvan Jegen, linux-kernel, kernel-janitors

After calling mantis_pci_init we have to jump to fail2 in order to call
the corresponding mantis_pci_exit. Similarly, after calling mantis_get_mac
we have already called mantis_pci_init and mantis_i2c_init so we need
to jump to fail3 if we want to call the corresponding exit functions.

Signed-off-by: Silvan Jegen <s.jegen@gmail.com>
---
 drivers/media/pci/mantis/mantis_cards.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
index e566061..71497d8 100644
--- a/drivers/media/pci/mantis/mantis_cards.c
+++ b/drivers/media/pci/mantis/mantis_cards.c
@@ -183,7 +183,7 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 	err = mantis_pci_init(mantis);
 	if (err) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
-		goto fail1;
+		goto fail2;
 	}
 
 	err = mantis_stream_control(mantis, STREAM_TO_HIF);
@@ -201,7 +201,7 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 	err = mantis_get_mac(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
-		goto fail2;
+		goto fail3;
 	}
 
 	err = mantis_dma_init(mantis);
-- 
2.2.2


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

* Re: [PATCH 1/2] [media] mantis: Move jump label to activate dead code
  2015-02-15 12:11 ` [PATCH 1/2] [media] mantis: Move jump label to activate dead code Silvan Jegen
@ 2015-02-16  9:04   ` Dan Carpenter
  2015-02-17  9:48     ` Silvan Jegen
  2015-03-22 17:16     ` [PATCH v2] [media] mantis: fix error handling Silvan Jegen
  0 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2015-02-16  9:04 UTC (permalink / raw)
  To: Silvan Jegen
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, kernel-janitors

On Sun, Feb 15, 2015 at 01:11:04PM +0100, Silvan Jegen wrote:
> diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
> index 801fc55..e566061 100644
> --- a/drivers/media/pci/mantis/mantis_cards.c
> +++ b/drivers/media/pci/mantis/mantis_cards.c
> @@ -215,10 +215,11 @@ static int mantis_pci_probe(struct pci_dev *pdev,
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
>  		goto fail4;
>  	}
> +
>  	err = mantis_uart_init(mantis);
>  	if (err < 0) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
> -		goto fail6;
> +		goto fail5;
>  	}
>  
>  	devs++;
> @@ -226,10 +227,10 @@ static int mantis_pci_probe(struct pci_dev *pdev,
>  	return err;
>  
>  
> +fail5:
>  	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);
>  	mantis_uart_exit(mantis);
>  
> -fail6:
>  fail4:
>  	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
>  	mantis_dma_exit(mantis);

This patch isn't right, I'm afraid.  The person who wrote this driver
deliberately added some dead error handling code in case we change it
later and need to activate it.  It's an ugly thing to do because it
causes static checker warnings, and confusion, and, in real life, then
we are not ever going to need to activate it.  It's defensive
programming but we don't do defensive programming.
http://lwn.net/Articles/604813/  Just delete this dead code.

Also this code uses GW-BASIC style numbered gotos.  So ugly!  The label
names should be based on what the label location does.  Eg
"err_uart_exit", "err_dma_exit".  I have written an essay about label
names:  https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ

In theory, we should be calling mantis_dvb_exit() if mantis_uart_init()
fails.  In reality, it can't fail but it's still wrong to leave that
out.

These patches would be easier to review if you just folded them into one
patch.  Call it "fix error error handling" or something.

regards,
dan carpenter

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

* Re: [PATCH 1/2] [media] mantis: Move jump label to activate dead code
  2015-02-16  9:04   ` Dan Carpenter
@ 2015-02-17  9:48     ` Silvan Jegen
  2015-03-22 17:16     ` [PATCH v2] [media] mantis: fix error handling Silvan Jegen
  1 sibling, 0 replies; 9+ messages in thread
From: Silvan Jegen @ 2015-02-17  9:48 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, kernel-janitors

Thanks for the review, Dan!

On Mon, Feb 16, 2015 at 10:04 AM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:
> On Sun, Feb 15, 2015 at 01:11:04PM +0100, Silvan Jegen wrote:
>> diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
>> index 801fc55..e566061 100644
>> --- a/drivers/media/pci/mantis/mantis_cards.c
>> +++ b/drivers/media/pci/mantis/mantis_cards.c
>> @@ -215,10 +215,11 @@ static int mantis_pci_probe(struct pci_dev *pdev,
>>               dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
>>               goto fail4;
>>       }
>> +
>>       err = mantis_uart_init(mantis);
>>       if (err < 0) {
>>               dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
>> -             goto fail6;
>> +             goto fail5;
>>       }
>>
>>       devs++;
>> @@ -226,10 +227,10 @@ static int mantis_pci_probe(struct pci_dev *pdev,
>>       return err;
>>
>>
>> +fail5:
>>       dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);
>>       mantis_uart_exit(mantis);
>>
>> -fail6:
>>  fail4:
>>       dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
>>       mantis_dma_exit(mantis);
>
> This patch isn't right, I'm afraid.  The person who wrote this driver
> deliberately added some dead error handling code in case we change it
> later and need to activate it.  It's an ugly thing to do because it
> causes static checker warnings, and confusion, and, in real life, then
> we are not ever going to need to activate it.  It's defensive
> programming but we don't do defensive programming.
> http://lwn.net/Articles/604813/  Just delete this dead code.

I will do that.


> Also this code uses GW-BASIC style numbered gotos.  So ugly!  The label
> names should be based on what the label location does.  Eg
> "err_uart_exit", "err_dma_exit".  I have written an essay about label
> names:  https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ
>
> In theory, we should be calling mantis_dvb_exit() if mantis_uart_init()
> fails.  In reality, it can't fail but it's still wrong to leave that
> out.

In the next version of the patch, I will change the names of the goto
labels accordingly. I will add the mantis_dvb_exit() call as well.


> These patches would be easier to review if you just folded them into one
> patch.  Call it "fix error error handling" or something.

Ok, I will fold the second patch into the first one replacing the goto
label names with more appropriate ones. In the first patch I will just
delete the dead code and change the jump labels to be more
descriptive.

I will leave for holidays at the end of the week so it's probably
better if I wait with sending the new version of the patch until I am
back.


Thanks again,

Silvan

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

* [PATCH v2] [media] mantis: fix error handling
  2015-02-16  9:04   ` Dan Carpenter
  2015-02-17  9:48     ` Silvan Jegen
@ 2015-03-22 17:16     ` Silvan Jegen
  2015-03-22 22:48       ` Dan Carpenter
  1 sibling, 1 reply; 9+ messages in thread
From: Silvan Jegen @ 2015-03-22 17:16 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, linux-media
  Cc: Silvan Jegen, linux-kernel, kernel-janitors, Dan Carpenter

Remove dead code, make goto label names more expressive and add a label
in order to call mantis_dvb_exit if mantis_uart_init fails.

Also make sure that mantis_pci_exit is called if we fail the
mantis_stream_control call and that we call mantis_i2c_exit if
mantis_get_mac fails.

Signed-off-by: Silvan Jegen <s.jegen@gmail.com>
---
V2 Changes (due to Dan Carpenter's review):
	- Remove dead code, do not activate it
	- Make goto labels more expressive
	- Add a call to mantis_dvb_exit

 drivers/media/pci/mantis/mantis_cards.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
index 801fc55..70df61e 100644
--- a/drivers/media/pci/mantis/mantis_cards.c
+++ b/drivers/media/pci/mantis/mantis_cards.c
@@ -170,7 +170,7 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 	if (mantis == NULL) {
 		printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
 		err = -ENOMEM;
-		goto fail0;
+		return err;
 	}
 
 	mantis->num		= devs;
@@ -183,70 +183,69 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 	err = mantis_pci_init(mantis);
 	if (err) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
-		goto fail1;
+		goto err_free_mantis;
 	}
 
 	err = mantis_stream_control(mantis, STREAM_TO_HIF);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
-		goto fail1;
+		goto err_pci_exit;
 	}
 
 	err = mantis_i2c_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
-		goto fail2;
+		goto err_pci_exit;
 	}
 
 	err = mantis_get_mac(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
-		goto fail2;
+		goto err_i2c_exit;
 	}
 
 	err = mantis_dma_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
-		goto fail3;
+		goto err_i2c_exit;
 	}
 
 	err = mantis_dvb_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
-		goto fail4;
+		goto err_dma_exit;
 	}
+
 	err = mantis_uart_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
-		goto fail6;
+		goto err_dvb_exit;
 	}
 
 	devs++;
 
 	return err;
 
+err_dvb_exit:
+	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err);
+	mantis_dvb_exit(mantis);
 
-	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);
-	mantis_uart_exit(mantis);
-
-fail6:
-fail4:
+err_dma_exit:
 	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
 	mantis_dma_exit(mantis);
 
-fail3:
+err_i2c_exit:
 	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
 	mantis_i2c_exit(mantis);
 
-fail2:
+err_pci_exit:
 	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
 	mantis_pci_exit(mantis);
 
-fail1:
+err_free_mantis:
 	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
 	kfree(mantis);
 
-fail0:
 	return err;
 }
 
-- 
2.3.3


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

* Re: [PATCH v2] [media] mantis: fix error handling
  2015-03-22 17:16     ` [PATCH v2] [media] mantis: fix error handling Silvan Jegen
@ 2015-03-22 22:48       ` Dan Carpenter
  2015-03-23 16:25         ` [PATCH V3] " Silvan Jegen
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2015-03-22 22:48 UTC (permalink / raw)
  To: Silvan Jegen
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, kernel-janitors

Good, but still a couple nits.

On Sun, Mar 22, 2015 at 06:16:18PM +0100, Silvan Jegen wrote:
> --- a/drivers/media/pci/mantis/mantis_cards.c
> +++ b/drivers/media/pci/mantis/mantis_cards.c
> @@ -170,7 +170,7 @@ static int mantis_pci_probe(struct pci_dev *pdev,
>  	if (mantis == NULL) {
>  		printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
>  		err = -ENOMEM;
> -		goto fail0;
> +		return err;

Just:
		return -ENOMEM;


>  	}
>  
>  	mantis->num		= devs;
> @@ -183,70 +183,69 @@ static int mantis_pci_probe(struct pci_dev *pdev,
>  	err = mantis_pci_init(mantis);
>  	if (err) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
> -		goto fail1;
> +		goto err_free_mantis;
>  	}
>  
>  	err = mantis_stream_control(mantis, STREAM_TO_HIF);
>  	if (err < 0) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
> -		goto fail1;
> +		goto err_pci_exit;
>  	}
>  
>  	err = mantis_i2c_init(mantis);
>  	if (err < 0) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
> -		goto fail2;
> +		goto err_pci_exit;
>  	}
>  
>  	err = mantis_get_mac(mantis);
>  	if (err < 0) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
> -		goto fail2;
> +		goto err_i2c_exit;
>  	}
>  
>  	err = mantis_dma_init(mantis);
>  	if (err < 0) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
> -		goto fail3;
> +		goto err_i2c_exit;
>  	}
>  
>  	err = mantis_dvb_init(mantis);
>  	if (err < 0) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
> -		goto fail4;
> +		goto err_dma_exit;
>  	}
> +
>  	err = mantis_uart_init(mantis);
>  	if (err < 0) {
>  		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
> -		goto fail6;
> +		goto err_dvb_exit;
>  	}
>  
>  	devs++;
>  
>  	return err;

	return 0;

That was in the original, but let's just clean it up as well.

>  
> +err_dvb_exit:
> +	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err);
> +	mantis_dvb_exit(mantis);
>  
> -	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);
> -	mantis_uart_exit(mantis);
> -
> -fail6:
> -fail4:
> +err_dma_exit:
>  	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
>  	mantis_dma_exit(mantis);
>  
> -fail3:
> +err_i2c_exit:
>  	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
>  	mantis_i2c_exit(mantis);
>  
> -fail2:
> +err_pci_exit:
>  	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
>  	mantis_pci_exit(mantis);
>  
> -fail1:
> +err_free_mantis:
>  	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
>  	kfree(mantis);


Remove all these dprintks in the error handling.

regards,
dan carpenter


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

* [PATCH V3] [media] mantis: fix error handling
  2015-03-22 22:48       ` Dan Carpenter
@ 2015-03-23 16:25         ` Silvan Jegen
  2015-03-23 16:32           ` Dan Carpenter
  0 siblings, 1 reply; 9+ messages in thread
From: Silvan Jegen @ 2015-03-23 16:25 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, linux-media
  Cc: Silvan Jegen, linux-kernel, kernel-janitors, Dan Carpenter

Remove dead code, make goto label names more expressive and add a label
in order to call mantis_dvb_exit if mantis_uart_init fails.

Also make sure that mantis_pci_exit is called if we fail the
mantis_stream_control call and that we call mantis_i2c_exit if
mantis_get_mac fails.

Signed-off-by: Silvan Jegen <s.jegen@gmail.com>
---
V3 Changes (due to Dan Carpenter's and Walter Harms' reviews):
	- return -ENOMEM/0 directly
  - remove dprintk calls in the error handling part

V2 Changes (due to Dan Carpenter's review):
	- Remove dead code, do not activate it
	- Make goto labels more expressive
	- Add a call to mantis_dvb_exit

 drivers/media/pci/mantis/mantis_cards.c | 39 ++++++++++++++-------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
index 801fc55..9861a8c 100644
--- a/drivers/media/pci/mantis/mantis_cards.c
+++ b/drivers/media/pci/mantis/mantis_cards.c
@@ -169,8 +169,7 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 	mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);
 	if (mantis == NULL) {
 		printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
-		err = -ENOMEM;
-		goto fail0;
+		return -ENOMEM;
 	}
 
 	mantis->num		= devs;
@@ -183,70 +182,64 @@ static int mantis_pci_probe(struct pci_dev *pdev,
 	err = mantis_pci_init(mantis);
 	if (err) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
-		goto fail1;
+		goto err_free_mantis;
 	}
 
 	err = mantis_stream_control(mantis, STREAM_TO_HIF);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
-		goto fail1;
+		goto err_pci_exit;
 	}
 
 	err = mantis_i2c_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
-		goto fail2;
+		goto err_pci_exit;
 	}
 
 	err = mantis_get_mac(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
-		goto fail2;
+		goto err_i2c_exit;
 	}
 
 	err = mantis_dma_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
-		goto fail3;
+		goto err_i2c_exit;
 	}
 
 	err = mantis_dvb_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
-		goto fail4;
+		goto err_dma_exit;
 	}
+
 	err = mantis_uart_init(mantis);
 	if (err < 0) {
 		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
-		goto fail6;
+		goto err_dvb_exit;
 	}
 
 	devs++;
 
-	return err;
-
+	return 0;
 
-	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);
-	mantis_uart_exit(mantis);
+err_dvb_exit:
+	mantis_dvb_exit(mantis);
 
-fail6:
-fail4:
-	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
+err_dma_exit:
 	mantis_dma_exit(mantis);
 
-fail3:
-	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
+err_i2c_exit:
 	mantis_i2c_exit(mantis);
 
-fail2:
-	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
+err_pci_exit:
 	mantis_pci_exit(mantis);
 
-fail1:
-	dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
+err_free_mantis:
 	kfree(mantis);
 
-fail0:
 	return err;
 }
 
-- 
2.3.3


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

* Re: [PATCH V3] [media] mantis: fix error handling
  2015-03-23 16:25         ` [PATCH V3] " Silvan Jegen
@ 2015-03-23 16:32           ` Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2015-03-23 16:32 UTC (permalink / raw)
  To: Silvan Jegen
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, kernel-janitors

On Mon, Mar 23, 2015 at 05:25:53PM +0100, Silvan Jegen wrote:
> Remove dead code, make goto label names more expressive and add a label
> in order to call mantis_dvb_exit if mantis_uart_init fails.
> 
> Also make sure that mantis_pci_exit is called if we fail the
> mantis_stream_control call and that we call mantis_i2c_exit if
> mantis_get_mac fails.
> 
> Signed-off-by: Silvan Jegen <s.jegen@gmail.com>

Looks great.  Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


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

end of thread, other threads:[~2015-03-23 16:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-15 12:11 [PATCH 0/2] [media] mantis: Fix goto labels Silvan Jegen
2015-02-15 12:11 ` [PATCH 1/2] [media] mantis: Move jump label to activate dead code Silvan Jegen
2015-02-16  9:04   ` Dan Carpenter
2015-02-17  9:48     ` Silvan Jegen
2015-03-22 17:16     ` [PATCH v2] [media] mantis: fix error handling Silvan Jegen
2015-03-22 22:48       ` Dan Carpenter
2015-03-23 16:25         ` [PATCH V3] " Silvan Jegen
2015-03-23 16:32           ` Dan Carpenter
2015-02-15 12:11 ` [PATCH 2/2] [media] mantis: Use correct goto labels for cleanup on error Silvan Jegen

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