Skip to contentSkip to conversation

drivers/net/ethernet/dec/tulip/dmfe.c: fix error return code

PATCH Applied Peter Senna Tschudin 4 participants 13 messages Oct 5, 2012 – Oct 7, 2012

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/20 drivers/net/ethernet/dec/tulip/dmfe.c: fix error return code

From: Peter Senna Tschudin <[email protected]>

The function dmfe_init_one() return 0 for success and negative value for most of its internal tests failures. There are three exceptions that are error cases going to err_out_*:. Fore this three cases the function abort its success execution path, but returns non negative value, making it dificult for a caller function to notice the error.

This patch fixes the error cases that do not return negative values.

This was found by Coccinelle, but the code change was made by hand. This patch is not robot generated.

A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>

---
Changes from V1:

	Updated commit message. See:
	http://www.kernelhub.org/?p=2&msg9319
 drivers/net/ethernet/dec/tulip/dmfe.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/ethernet/dec/tulip/dmfe.c +9 -3
index 4d6fe60..d23755e 100644
@@ -446,13 +446,17 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
 	/* Allocate Tx/Rx descriptor memory */
 	db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) *
 			DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr);
-	if (!db->desc_pool_ptr)
+	if (!db->desc_pool_ptr) {
+		err = -ENOMEM;
 		goto err_out_res;
+	}
 
 	db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
 			TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);
-	if (!db->buf_pool_ptr)
+	if (!db->buf_pool_ptr) {
+		err = -ENOMEM;
 		goto err_out_free_desc;
+	}
 
 	db->first_tx_desc = (struct tx_desc *) db->desc_pool_ptr;
 	db->first_tx_desc_dma = db->desc_pool_dma_ptr;
@@ -462,8 +466,10 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
 	db->chip_id = ent->driver_data;
 	/* IO type range. */
 	db->ioaddr = pci_iomap(pdev, 0, 0);
-	if (!db->ioaddr)
+	if (!db->ioaddr) {
+		err = -ENOMEM;
 		goto err_out_free_buf;
+	}
 
 	db->chip_revision = pdev->revision;
 	db->wol_mode = 0;
#1 lore raw

PATCH v2 2/20 drivers/net/ethernet/natsemi/natsemi.c: fix error return code

From: Peter Senna Tschudin <[email protected]>

The function natsemi_probe1() return 0 for success and negative value for most of its internal tests failures. There is one exception that is error case going to err_create_file:. Fore this error case the function abort its success execution path, but returns non negative value, making it difficult for a caller function to notice the error.

This patch fixes the error case that do not return negative value.

This was found by Coccinelle, but the code change was made by hand. This patch is not robot generated.

A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>

---
Changes from V1:

	Updated commit message. See:
	http://www.kernelhub.org/?p=2&msg9319
 drivers/net/ethernet/natsemi/natsemi.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/natsemi/natsemi.c +2 -2
index 5b61d12..dbaaa99 100644
@@ -947,8 +947,8 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
 	i = register_netdev(dev);
 	if (i)
 		goto err_register_netdev;
-
-	if (NATSEMI_CREATE_FILE(pdev, dspcfg_workaround))
+	i = NATSEMI_CREATE_FILE(pdev, dspcfg_workaround);
+	if (i)
 		goto err_create_file;
 
 	if (netif_msg_drv(np)) {
Acked-by on v2 2/20
#2 lore raw

Re: [PATCH 2/20 V2] drivers/net/ethernet/natsemi/natsemi.c: fix error return code

Peter Senna Tschudin <[email protected]> :
[...]

Quoted 5 lines

The function natsemi_probe1() return 0 for success and negative value for most of its internal tests failures. There is one exception that is error case going to err_create_file:. Fore this error case the function abort its success execution path, but returns non negative value, making it difficult for a caller function to notice the error.

Ok. natsemi_probe1() forgets to return a negative status code in one of its failure paths.

[...]

Quoted 1 line
Signature · 1 line
Ueimor
#4 lore raw

PATCH v2 3/20 drivers/net/can/sja1000/peak_pci.c: fix error return code

In reply to Peter Senna Tschudin

From: Peter Senna Tschudin <[email protected]>

The function peak_pci_probe() return 0 for success and negative value for most of its internal tests failures. There are two exceptions that are error cases going to failure_*:. Fore this two cases the function abort its success execution path, but returns non negative value, making it dificult for a caller function to notice the error.

This patch fixes the error cases that do not return negative values.

This was found by Coccinelle, but the code change was made by hand. This patch is not robot generated.

A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>

---
Change from V1:

	Updated commit message. See: 
	http://www.kernelhub.org/?p=2&msg9319
 drivers/net/can/sja1000/peak_pci.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/net/can/sja1000/peak_pci.c +2 -0
index f0a1296..f5b82ae 100644
@@ -583,12 +583,14 @@ static int __devinit peak_pci_probe(struct pci_dev *pdev,
 	cfg_base = pci_iomap(pdev, 0, PEAK_PCI_CFG_SIZE);
 	if (!cfg_base) {
 		dev_err(&pdev->dev, "failed to map PCI resource #0\n");
+		err = -ENOMEM;
 		goto failure_release_regions;
 	}
 
 	reg_base = pci_iomap(pdev, 1, PEAK_PCI_CHAN_SIZE * channels);
 	if (!reg_base) {
 		dev_err(&pdev->dev, "failed to map PCI resource #1\n");
+		err = -ENOMEM;
 		goto failure_unmap_cfg_base;
 	}
 
#5 lore raw

Re: [PATCH 3/20 V2] drivers/net/can/sja1000/peak_pci.c: fix error return code

Quoted 33 lines · Peter Senna Tschudin

From: Peter Senna Tschudin <[email protected]>

The function peak_pci_probe() return 0 for success and negative value for most of its internal tests failures. There are two exceptions that are error cases going to failure_*:. Fore this two cases the function abort its success execution path, but returns non negative value, making it dificult for a caller function to notice the error.

This patch fixes the error cases that do not return negative values.

This was found by Coccinelle, but the code change was made by hand. This patch is not robot generated.

A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>

Quoted 1 line

Too late, v1 of this patch is already in net/master

regards, Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#7 lore raw

PATCH v2 4/20 drivers/net/can/sja1000/peak_pcmcia.c: fix error return code

In reply to Peter Senna Tschudin

From: Peter Senna Tschudin <[email protected]>

The function pcan_probe() return 0 for success and negative value for most of its internal tests failures. There is one exception that is error case going to probe_err_4:. Fore this error case, the function abort its success execution path but returns non negative value, making it difficult for a caller function to notice the error.

This patch fixes the error case that do not return negative value.

This was found by Coccinelle, but the code change was made by hand. This patch is not robot generated.

A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>

---
Change from V1:
Updated commit message. See:
http://www.kernelhub.org/?p=2&msg9319

 drivers/net/can/sja1000/peak_pcmcia.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/sja1000/peak_pcmcia.c +3 -1
index ec6bd9d..272a85f 100644
@@ -686,8 +686,10 @@ static int __devinit pcan_probe(struct pcmcia_device *pdev)
 
 	/* detect available channels */
 	pcan_add_channels(card);
-	if (!card->chan_count)
+	if (!card->chan_count) {
+		err = -ENOMEM;
 		goto probe_err_4;
+	}
 
 	/* init the timer which controls the leds */
 	init_timer(&card->led_timer);
#8 lore raw

Re: [PATCH 4/20 V2] drivers/net/can/sja1000/peak_pcmcia.c: fix error return code

Quoted 33 lines · Peter Senna Tschudin

From: Peter Senna Tschudin <[email protected]>

The function pcan_probe() return 0 for success and negative value for most of its internal tests failures. There is one exception that is error case going to probe_err_4:. Fore this error case, the function abort its success execution path but returns non negative value, making it difficult for a caller function to notice the error.

This patch fixes the error case that do not return negative value.

This was found by Coccinelle, but the code change was made by hand. This patch is not robot generated.

A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>

Quoted 1 line

Too late, v1 of this patch is already in net/master

regards, Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#10 lore raw

PATCH v2 5/20 drivers/net/ethernet/sis/sis900.c: fix error return code

In reply to Peter Senna Tschudin

From: Peter Senna Tschudin <[email protected]>

The function sis900_probe() return 0 for success and negative value for most of its internal tests failures. There is one exception that is error case going to err_out_cleardev:. Fore this error case, the function abort its success execution path, but returns non negative value, making it difficult for a caller function to notice the error.

This patch fixes the error case that do not return negative value.

This was found by Coccinelle, but the code change was made by hand. This patch is not robot generated.

A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1

    when != &ret

*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>

---
Change from V1:
Updated commit message. See:
http://www.kernelhub.org/?p=2&msg9319

 drivers/net/ethernet/sis/sis900.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/sis/sis900.c +3 -1
index 203d9c6..fb9f6b3 100644
@@ -478,8 +478,10 @@ static int __devinit sis900_probe(struct pci_dev *pci_dev,
 
 	/* IO region. */
 	ioaddr = pci_iomap(pci_dev, 0, 0);
-	if (!ioaddr)
+	if (!ioaddr) {
+		ret = -ENOMEM;
 		goto err_out_cleardev;
+	}
 
 	sis_priv = netdev_priv(net_dev);
 	sis_priv->ioaddr = ioaddr;
maintainer Applied
#11 lore raw

Re: [PATCH 5/20 V2] drivers/net/ethernet/sis/sis900.c: fix error return code

Applied.