* [PATCH v2] [media] mantis: fix error handling
@ 2015-03-22 17:16 ` Silvan Jegen
0 siblings, 0 replies; 20+ 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] 20+ messages in thread* Re: [PATCH v2] [media] mantis: fix error handling
2015-03-22 17:16 ` Silvan Jegen
@ 2015-03-22 19:33 ` walter harms
-1 siblings, 0 replies; 20+ messages in thread
From: walter harms @ 2015-03-22 19:33 UTC (permalink / raw)
To: Silvan Jegen
Cc: Mauro Carvalho Chehab, linux-media, kernel-janitors,
Dan Carpenter
Am 22.03.2015 18:16, schrieb Silvan Jegen:
> 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;
>
Hi Silvan Jegen,
i found the dprintk() a bit confusing, if i understand the code correctly it will always print on error:
the dprintf found in if (err<0) like :
dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
and then
dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err);
maybe this is more a question for the maintainer, but this seems a bit useless.
re,
wh
> +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;
> }
>
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v2] [media] mantis: fix error handling
@ 2015-03-22 19:33 ` walter harms
0 siblings, 0 replies; 20+ messages in thread
From: walter harms @ 2015-03-22 19:33 UTC (permalink / raw)
To: Silvan Jegen
Cc: Mauro Carvalho Chehab, linux-media, kernel-janitors,
Dan Carpenter
Am 22.03.2015 18:16, schrieb Silvan Jegen:
> 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;
>
Hi Silvan Jegen,
i found the dprintk() a bit confusing, if i understand the code correctly it will always print on error:
the dprintf found in if (err<0) like :
dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
and then
dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err);
maybe this is more a question for the maintainer, but this seems a bit useless.
re,
wh
> +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;
> }
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2] [media] mantis: fix error handling
2015-03-22 17:16 ` Silvan Jegen
@ 2015-03-22 22:48 ` Dan Carpenter
-1 siblings, 0 replies; 20+ 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] 20+ messages in thread* Re: [PATCH v2] [media] mantis: fix error handling
@ 2015-03-22 22:48 ` Dan Carpenter
0 siblings, 0 replies; 20+ 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] 20+ messages in thread* [PATCH V3] [media] mantis: fix error handling
2015-03-22 22:48 ` Dan Carpenter
@ 2015-03-23 16:25 ` Silvan Jegen
-1 siblings, 0 replies; 20+ 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] 20+ messages in thread* [PATCH V3] [media] mantis: fix error handling
@ 2015-03-23 16:25 ` Silvan Jegen
0 siblings, 0 replies; 20+ 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] 20+ messages in thread* Re: [PATCH V3] [media] mantis: fix error handling
2015-03-23 16:25 ` Silvan Jegen
@ 2015-03-23 16:32 ` Dan Carpenter
-1 siblings, 0 replies; 20+ 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] 20+ messages in thread
* Re: [PATCH V3] [media] mantis: fix error handling
@ 2015-03-23 16:32 ` Dan Carpenter
0 siblings, 0 replies; 20+ 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] 20+ messages in thread