All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] FMan MAC: Improve exception handling in mac_probe()
@ 2019-11-09  8:55 ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  8:55 UTC (permalink / raw)
  To: netdev, David S. Miller, Igal Liberman, Madalin Bucur
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:44:55 +0100

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
  Add missing put_device() calls
  Use common error handling code
  Return directly after a failed devm_kzalloc()

 drivers/net/ethernet/freescale/fman/mac.c | 73 ++++++++++++-----------
 1 file changed, 39 insertions(+), 34 deletions(-)

--
2.24.0


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

* [PATCH 0/3] FMan MAC: Improve exception handling in mac_probe()
@ 2019-11-09  8:55 ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  8:55 UTC (permalink / raw)
  To: netdev, David S. Miller, Igal Liberman, Madalin Bucur
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:44:55 +0100

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
  Add missing put_device() calls
  Use common error handling code
  Return directly after a failed devm_kzalloc()

 drivers/net/ethernet/freescale/fman/mac.c | 73 ++++++++++++-----------
 1 file changed, 39 insertions(+), 34 deletions(-)

--
2.24.0

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

* [PATCH 1/3] fsl/fman: Add missing put_device() calls in mac_probe()
  2019-11-09  8:55 ` Markus Elfring
@ 2019-11-09  9:00   ` Markus Elfring
  -1 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:00 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors, Wen Yang

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 08:14:35 +0100

A coccicheck run provided information like the following.

drivers/net/ethernet/freescale/fman/mac.c:874:1-7: ERROR: missing put_device;
call of_find_device_by_node on line 659, but without a corresponding
object release within this function.
drivers/net/ethernet/freescale/fman/mac.c:874:1-7: ERROR: missing put_device;
call of_find_device_by_node on line 760, but without a corresponding
object release within this function.

Generated by: scripts/coccinelle/free/put_device.cocci

Thus adjust jump targets to fix the exception handling for this
function implementation.

Fixes: 3933961682a30ae7d405cda344c040a129fea422 ("fsl/fman: Add FMan MAC driver")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 28 ++++++++++++++---------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index f0806ace1ae2..e0680257532c 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -668,7 +668,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
 		err = -EINVAL;
-		goto _return_of_node_put;
+		goto _put_device;
 	}
 	/* cell-index 0 => FMan id 1 */
 	fman_id = (u8)(val + 1);
@@ -677,7 +677,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (!priv->fman) {
 		dev_err(dev, "fman_bind(%pOF) failed\n", dev_node);
 		err = -ENODEV;
-		goto _return_of_node_put;
+		goto _put_device;
 	}

 	of_node_put(dev_node);
@@ -687,7 +687,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (err < 0) {
 		dev_err(dev, "of_address_to_resource(%pOF) = %d\n",
 			mac_node, err);
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	mac_dev->res = __devm_request_region(dev,
@@ -697,7 +697,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (!mac_dev->res) {
 		dev_err(dev, "__devm_request_mem_region(mac) failed\n");
 		err = -EBUSY;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	priv->vaddr = devm_ioremap(dev, mac_dev->res->start,
@@ -705,12 +705,12 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (!priv->vaddr) {
 		dev_err(dev, "devm_ioremap() failed\n");
 		err = -EIO;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	if (!of_device_is_available(mac_node)) {
 		err = -ENODEV;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	/* Get the cell-index */
@@ -718,7 +718,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
 		err = -EINVAL;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}
 	priv->cell_index = (u8)val;

@@ -727,7 +727,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (IS_ERR(mac_addr)) {
 		dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
 		err = -EINVAL;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}
 	ether_addr_copy(mac_dev->addr, mac_addr);

@@ -737,14 +737,14 @@ static int mac_probe(struct platform_device *_of_dev)
 		dev_err(dev, "of_count_phandle_with_args(%pOF, fsl,fman-ports) failed\n",
 			mac_node);
 		err = nph;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	if (nph != ARRAY_SIZE(mac_dev->port)) {
 		dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
 			mac_node);
 		err = -EINVAL;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -770,7 +770,7 @@ static int mac_probe(struct platform_device *_of_dev)
 			dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
 				dev_node);
 			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _put_device;
 		}
 		of_node_put(dev_node);
 	}
@@ -866,6 +866,12 @@ static int mac_probe(struct platform_device *_of_dev)

 	goto _return;

+_put_parent_device:
+	put_device(&of_dev->dev);
+	goto _return_of_get_parent;
+
+_put_device:
+	put_device(&of_dev->dev);
 _return_of_node_put:
 	of_node_put(dev_node);
 _return_of_get_parent:
--
2.24.0


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

* [PATCH 1/3] fsl/fman: Add missing put_device() calls in mac_probe()
@ 2019-11-09  9:00   ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:00 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors, Wen Yang

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 08:14:35 +0100

A coccicheck run provided information like the following.

drivers/net/ethernet/freescale/fman/mac.c:874:1-7: ERROR: missing put_device;
call of_find_device_by_node on line 659, but without a corresponding
object release within this function.
drivers/net/ethernet/freescale/fman/mac.c:874:1-7: ERROR: missing put_device;
call of_find_device_by_node on line 760, but without a corresponding
object release within this function.

Generated by: scripts/coccinelle/free/put_device.cocci

Thus adjust jump targets to fix the exception handling for this
function implementation.

Fixes: 3933961682a30ae7d405cda344c040a129fea422 ("fsl/fman: Add FMan MAC driver")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 28 ++++++++++++++---------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index f0806ace1ae2..e0680257532c 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -668,7 +668,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
 		err = -EINVAL;
-		goto _return_of_node_put;
+		goto _put_device;
 	}
 	/* cell-index 0 => FMan id 1 */
 	fman_id = (u8)(val + 1);
@@ -677,7 +677,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (!priv->fman) {
 		dev_err(dev, "fman_bind(%pOF) failed\n", dev_node);
 		err = -ENODEV;
-		goto _return_of_node_put;
+		goto _put_device;
 	}

 	of_node_put(dev_node);
@@ -687,7 +687,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (err < 0) {
 		dev_err(dev, "of_address_to_resource(%pOF) = %d\n",
 			mac_node, err);
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	mac_dev->res = __devm_request_region(dev,
@@ -697,7 +697,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (!mac_dev->res) {
 		dev_err(dev, "__devm_request_mem_region(mac) failed\n");
 		err = -EBUSY;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	priv->vaddr = devm_ioremap(dev, mac_dev->res->start,
@@ -705,12 +705,12 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (!priv->vaddr) {
 		dev_err(dev, "devm_ioremap() failed\n");
 		err = -EIO;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	if (!of_device_is_available(mac_node)) {
 		err = -ENODEV;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	/* Get the cell-index */
@@ -718,7 +718,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
 		err = -EINVAL;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}
 	priv->cell_index = (u8)val;

@@ -727,7 +727,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (IS_ERR(mac_addr)) {
 		dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
 		err = -EINVAL;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}
 	ether_addr_copy(mac_dev->addr, mac_addr);

@@ -737,14 +737,14 @@ static int mac_probe(struct platform_device *_of_dev)
 		dev_err(dev, "of_count_phandle_with_args(%pOF, fsl,fman-ports) failed\n",
 			mac_node);
 		err = nph;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	if (nph != ARRAY_SIZE(mac_dev->port)) {
 		dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
 			mac_node);
 		err = -EINVAL;
-		goto _return_of_get_parent;
+		goto _put_parent_device;
 	}

 	for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -770,7 +770,7 @@ static int mac_probe(struct platform_device *_of_dev)
 			dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
 				dev_node);
 			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _put_device;
 		}
 		of_node_put(dev_node);
 	}
@@ -866,6 +866,12 @@ static int mac_probe(struct platform_device *_of_dev)

 	goto _return;

+_put_parent_device:
+	put_device(&of_dev->dev);
+	goto _return_of_get_parent;
+
+_put_device:
+	put_device(&of_dev->dev);
 _return_of_node_put:
 	of_node_put(dev_node);
 _return_of_get_parent:
--
2.24.0

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

* [PATCH 2/3] fsl/fman: Use common error handling code in mac_probe()
  2019-11-09  8:55 ` Markus Elfring
@ 2019-11-09  9:03   ` Markus Elfring
  -1 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:03 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:13:01 +0100

Adjust jump targets so that exception handling code can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 42 ++++++++++++-----------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index e0680257532c..7fbd7cc24ede 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -659,16 +659,14 @@ static int mac_probe(struct platform_device *_of_dev)
 	of_dev = of_find_device_by_node(dev_node);
 	if (!of_dev) {
 		dev_err(dev, "of_find_device_by_node(%pOF) failed\n", dev_node);
-		err = -EINVAL;
-		goto _return_of_node_put;
+		goto _e_inval_put_node;
 	}

 	/* Get the FMan cell-index */
 	err = of_property_read_u32(dev_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
-		err = -EINVAL;
-		goto _put_device;
+		goto _e_inval_put_device;
 	}
 	/* cell-index 0 => FMan id 1 */
 	fman_id = (u8)(val + 1);
@@ -717,8 +715,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = of_property_read_u32(mac_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	priv->cell_index = (u8)val;

@@ -726,8 +723,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	mac_addr = of_get_mac_address(mac_node);
 	if (IS_ERR(mac_addr)) {
 		dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	ether_addr_copy(mac_dev->addr, mac_addr);

@@ -743,8 +739,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (nph != ARRAY_SIZE(mac_dev->port)) {
 		dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
 			mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}

 	for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -753,24 +748,21 @@ static int mac_probe(struct platform_device *_of_dev)
 		if (!dev_node) {
 			dev_err(dev, "of_parse_phandle(%pOF, fsl,fman-ports) failed\n",
 				mac_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		of_dev = of_find_device_by_node(dev_node);
 		if (!of_dev) {
 			dev_err(dev, "of_find_device_by_node(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		mac_dev->port[i] = fman_port_bind(&of_dev->dev);
 		if (!mac_dev->port[i]) {
 			dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _put_device;
+			goto _e_inval_put_device;
 		}
 		of_node_put(dev_node);
 	}
@@ -821,8 +813,7 @@ static int mac_probe(struct platform_device *_of_dev)
 		phy = of_phy_find_device(mac_dev->phy_node);
 		if (!phy) {
 			err = -EINVAL;
-			of_node_put(mac_dev->phy_node);
-			goto _return_of_get_parent;
+			goto _put_phy_node;
 		}

 		priv->fixed_link->link = phy->link;
@@ -837,8 +828,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = mac_dev->init(mac_dev);
 	if (err < 0) {
 		dev_err(dev, "mac_dev->init() = %d\n", err);
-		of_node_put(mac_dev->phy_node);
-		goto _return_of_get_parent;
+		goto _put_phy_node;
 	}

 	/* pause frame autonegotiation enabled */
@@ -866,10 +856,22 @@ static int mac_probe(struct platform_device *_of_dev)

 	goto _return;

+_put_phy_node:
+	of_node_put(mac_dev->phy_node);
+	goto _return_of_get_parent;
+
+_e_inval_put_node:
+	err = -EINVAL;
+	goto _return_of_node_put;
+
+_e_inval_put_parent_device:
+	err = -EINVAL;
 _put_parent_device:
 	put_device(&of_dev->dev);
 	goto _return_of_get_parent;

+_e_inval_put_device:
+	err = -EINVAL;
 _put_device:
 	put_device(&of_dev->dev);
 _return_of_node_put:
--
2.24.0


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

* [PATCH 2/3] fsl/fman: Use common error handling code in mac_probe()
  2019-11-09  8:55 ` Markus Elfring
@ 2019-11-09  9:03   ` Markus Elfring
  -1 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:03 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:13:01 +0100

Adjust jump targets so that exception handling code can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 42 ++++++++++++-----------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index e0680257532c..7fbd7cc24ede 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -659,16 +659,14 @@ static int mac_probe(struct platform_device *_of_dev)
 	of_dev = of_find_device_by_node(dev_node);
 	if (!of_dev) {
 		dev_err(dev, "of_find_device_by_node(%pOF) failed\n", dev_node);
-		err = -EINVAL;
-		goto _return_of_node_put;
+		goto _e_inval_put_node;
 	}

 	/* Get the FMan cell-index */
 	err = of_property_read_u32(dev_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
-		err = -EINVAL;
-		goto _put_device;
+		goto _e_inval_put_device;
 	}
 	/* cell-index 0 => FMan id 1 */
 	fman_id = (u8)(val + 1);
@@ -717,8 +715,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = of_property_read_u32(mac_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	priv->cell_index = (u8)val;

@@ -726,8 +723,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	mac_addr = of_get_mac_address(mac_node);
 	if (IS_ERR(mac_addr)) {
 		dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	ether_addr_copy(mac_dev->addr, mac_addr);

@@ -743,8 +739,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (nph != ARRAY_SIZE(mac_dev->port)) {
 		dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
 			mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}

 	for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -753,24 +748,21 @@ static int mac_probe(struct platform_device *_of_dev)
 		if (!dev_node) {
 			dev_err(dev, "of_parse_phandle(%pOF, fsl,fman-ports) failed\n",
 				mac_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		of_dev = of_find_device_by_node(dev_node);
 		if (!of_dev) {
 			dev_err(dev, "of_find_device_by_node(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		mac_dev->port[i] = fman_port_bind(&of_dev->dev);
 		if (!mac_dev->port[i]) {
 			dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _put_device;
+			goto _e_inval_put_device;
 		}
 		of_node_put(dev_node);
 	}
@@ -821,8 +813,7 @@ static int mac_probe(struct platform_device *_of_dev)
 		phy = of_phy_find_device(mac_dev->phy_node);
 		if (!phy) {
 			err = -EINVAL;
-			of_node_put(mac_dev->phy_node);
-			goto _return_of_get_parent;
+			goto _put_phy_node;
 		}

 		priv->fixed_link->link = phy->link;
@@ -837,8 +828,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = mac_dev->init(mac_dev);
 	if (err < 0) {
 		dev_err(dev, "mac_dev->init() = %d\n", err);
-		of_node_put(mac_dev->phy_node);
-		goto _return_of_get_parent;
+		goto _put_phy_node;
 	}

 	/* pause frame autonegotiation enabled */
@@ -866,10 +856,22 @@ static int mac_probe(struct platform_device *_of_dev)

 	goto _return;

+_put_phy_node:
+	of_node_put(mac_dev->phy_node);
+	goto _return_of_get_parent;
+
+_e_inval_put_node:
+	err = -EINVAL;
+	goto _return_of_node_put;
+
+_e_inval_put_parent_device:
+	err = -EINVAL;
 _put_parent_device:
 	put_device(&of_dev->dev);
 	goto _return_of_get_parent;

+_e_inval_put_device:
+	err = -EINVAL;
 _put_device:
 	put_device(&of_dev->dev);
 _return_of_node_put:
--
2.24.0


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

* [PATCH 2/3] fsl/fman: Use common error handling code in mac_probe()
@ 2019-11-09  9:03   ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:03 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:13:01 +0100

Adjust jump targets so that exception handling code can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 42 ++++++++++++-----------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index e0680257532c..7fbd7cc24ede 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -659,16 +659,14 @@ static int mac_probe(struct platform_device *_of_dev)
 	of_dev = of_find_device_by_node(dev_node);
 	if (!of_dev) {
 		dev_err(dev, "of_find_device_by_node(%pOF) failed\n", dev_node);
-		err = -EINVAL;
-		goto _return_of_node_put;
+		goto _e_inval_put_node;
 	}

 	/* Get the FMan cell-index */
 	err = of_property_read_u32(dev_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
-		err = -EINVAL;
-		goto _put_device;
+		goto _e_inval_put_device;
 	}
 	/* cell-index 0 => FMan id 1 */
 	fman_id = (u8)(val + 1);
@@ -717,8 +715,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = of_property_read_u32(mac_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	priv->cell_index = (u8)val;

@@ -726,8 +723,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	mac_addr = of_get_mac_address(mac_node);
 	if (IS_ERR(mac_addr)) {
 		dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	ether_addr_copy(mac_dev->addr, mac_addr);

@@ -743,8 +739,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (nph != ARRAY_SIZE(mac_dev->port)) {
 		dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
 			mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}

 	for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -753,24 +748,21 @@ static int mac_probe(struct platform_device *_of_dev)
 		if (!dev_node) {
 			dev_err(dev, "of_parse_phandle(%pOF, fsl,fman-ports) failed\n",
 				mac_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		of_dev = of_find_device_by_node(dev_node);
 		if (!of_dev) {
 			dev_err(dev, "of_find_device_by_node(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		mac_dev->port[i] = fman_port_bind(&of_dev->dev);
 		if (!mac_dev->port[i]) {
 			dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _put_device;
+			goto _e_inval_put_device;
 		}
 		of_node_put(dev_node);
 	}
@@ -821,8 +813,7 @@ static int mac_probe(struct platform_device *_of_dev)
 		phy = of_phy_find_device(mac_dev->phy_node);
 		if (!phy) {
 			err = -EINVAL;
-			of_node_put(mac_dev->phy_node);
-			goto _return_of_get_parent;
+			goto _put_phy_node;
 		}

 		priv->fixed_link->link = phy->link;
@@ -837,8 +828,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = mac_dev->init(mac_dev);
 	if (err < 0) {
 		dev_err(dev, "mac_dev->init() = %d\n", err);
-		of_node_put(mac_dev->phy_node);
-		goto _return_of_get_parent;
+		goto _put_phy_node;
 	}

 	/* pause frame autonegotiation enabled */
@@ -866,10 +856,22 @@ static int mac_probe(struct platform_device *_of_dev)

 	goto _return;

+_put_phy_node:
+	of_node_put(mac_dev->phy_node);
+	goto _return_of_get_parent;
+
+_e_inval_put_node:
+	err = -EINVAL;
+	goto _return_of_node_put;
+
+_e_inval_put_parent_device:
+	err = -EINVAL;
 _put_parent_device:
 	put_device(&of_dev->dev);
 	goto _return_of_get_parent;

+_e_inval_put_device:
+	err = -EINVAL;
 _put_device:
 	put_device(&of_dev->dev);
 _return_of_node_put:
--
2.24.0

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

* [PATCH 2/3] fsl/fman: Use common error handling code in mac_probe()
@ 2019-11-09  9:03   ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:03 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:13:01 +0100

Adjust jump targets so that exception handling code can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 42 ++++++++++++-----------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index e0680257532c..7fbd7cc24ede 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -659,16 +659,14 @@ static int mac_probe(struct platform_device *_of_dev)
 	of_dev = of_find_device_by_node(dev_node);
 	if (!of_dev) {
 		dev_err(dev, "of_find_device_by_node(%pOF) failed\n", dev_node);
-		err = -EINVAL;
-		goto _return_of_node_put;
+		goto _e_inval_put_node;
 	}

 	/* Get the FMan cell-index */
 	err = of_property_read_u32(dev_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
-		err = -EINVAL;
-		goto _put_device;
+		goto _e_inval_put_device;
 	}
 	/* cell-index 0 => FMan id 1 */
 	fman_id = (u8)(val + 1);
@@ -717,8 +715,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = of_property_read_u32(mac_node, "cell-index", &val);
 	if (err) {
 		dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	priv->cell_index = (u8)val;

@@ -726,8 +723,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	mac_addr = of_get_mac_address(mac_node);
 	if (IS_ERR(mac_addr)) {
 		dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}
 	ether_addr_copy(mac_dev->addr, mac_addr);

@@ -743,8 +739,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	if (nph != ARRAY_SIZE(mac_dev->port)) {
 		dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
 			mac_node);
-		err = -EINVAL;
-		goto _put_parent_device;
+		goto _e_inval_put_parent_device;
 	}

 	for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -753,24 +748,21 @@ static int mac_probe(struct platform_device *_of_dev)
 		if (!dev_node) {
 			dev_err(dev, "of_parse_phandle(%pOF, fsl,fman-ports) failed\n",
 				mac_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		of_dev = of_find_device_by_node(dev_node);
 		if (!of_dev) {
 			dev_err(dev, "of_find_device_by_node(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _return_of_node_put;
+			goto _e_inval_put_node;
 		}

 		mac_dev->port[i] = fman_port_bind(&of_dev->dev);
 		if (!mac_dev->port[i]) {
 			dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
 				dev_node);
-			err = -EINVAL;
-			goto _put_device;
+			goto _e_inval_put_device;
 		}
 		of_node_put(dev_node);
 	}
@@ -821,8 +813,7 @@ static int mac_probe(struct platform_device *_of_dev)
 		phy = of_phy_find_device(mac_dev->phy_node);
 		if (!phy) {
 			err = -EINVAL;
-			of_node_put(mac_dev->phy_node);
-			goto _return_of_get_parent;
+			goto _put_phy_node;
 		}

 		priv->fixed_link->link = phy->link;
@@ -837,8 +828,7 @@ static int mac_probe(struct platform_device *_of_dev)
 	err = mac_dev->init(mac_dev);
 	if (err < 0) {
 		dev_err(dev, "mac_dev->init() = %d\n", err);
-		of_node_put(mac_dev->phy_node);
-		goto _return_of_get_parent;
+		goto _put_phy_node;
 	}

 	/* pause frame autonegotiation enabled */
@@ -866,10 +856,22 @@ static int mac_probe(struct platform_device *_of_dev)

 	goto _return;

+_put_phy_node:
+	of_node_put(mac_dev->phy_node);
+	goto _return_of_get_parent;
+
+_e_inval_put_node:
+	err = -EINVAL;
+	goto _return_of_node_put;
+
+_e_inval_put_parent_device:
+	err = -EINVAL;
 _put_parent_device:
 	put_device(&of_dev->dev);
 	goto _return_of_get_parent;

+_e_inval_put_device:
+	err = -EINVAL;
 _put_device:
 	put_device(&of_dev->dev);
 _return_of_node_put:
--
2.24.0

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

* [PATCH 3/3] fsl/fman: Return directly after a failed devm_kzalloc() in mac_probe()
  2019-11-09  8:55 ` Markus Elfring
@ 2019-11-09  9:06   ` Markus Elfring
  -1 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:06 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:26:12 +0100

Return directly after a call of the function “devm_kzalloc” failed
at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index 7fbd7cc24ede..75614e2ebda3 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -614,15 +614,12 @@ static int mac_probe(struct platform_device *_of_dev)
 	mac_node = dev->of_node;

 	mac_dev = devm_kzalloc(dev, sizeof(*mac_dev), GFP_KERNEL);
-	if (!mac_dev) {
-		err = -ENOMEM;
-		goto _return;
-	}
+	if (!mac_dev)
+		return -ENOMEM;
+
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		err = -ENOMEM;
-		goto _return;
-	}
+	if (!priv)
+		return -ENOMEM;

 	/* Save private information */
 	mac_dev->priv = priv;
--
2.24.0


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

* [PATCH 3/3] fsl/fman: Return directly after a failed devm_kzalloc() in mac_probe()
@ 2019-11-09  9:06   ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-09  9:06 UTC (permalink / raw)
  To: netdev, David S. Miller, Madalin Bucur; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Nov 2019 09:26:12 +0100

Return directly after a call of the function “devm_kzalloc” failed
at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/freescale/fman/mac.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index 7fbd7cc24ede..75614e2ebda3 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -614,15 +614,12 @@ static int mac_probe(struct platform_device *_of_dev)
 	mac_node = dev->of_node;

 	mac_dev = devm_kzalloc(dev, sizeof(*mac_dev), GFP_KERNEL);
-	if (!mac_dev) {
-		err = -ENOMEM;
-		goto _return;
-	}
+	if (!mac_dev)
+		return -ENOMEM;
+
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		err = -ENOMEM;
-		goto _return;
-	}
+	if (!priv)
+		return -ENOMEM;

 	/* Save private information */
 	mac_dev->priv = priv;
--
2.24.0

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

* Re: [PATCH 1/3] fsl/fman: Add missing put_device() calls in mac_probe()
  2019-11-09  9:00   ` Markus Elfring
@ 2019-11-10  9:15     ` Markus Elfring
  -1 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-10  9:15 UTC (permalink / raw)
  To: netdev, David S. Miller; +Cc: LKML, kernel-janitors, Madalin Bucur, Wen Yang

> Generated by: scripts/coccinelle/free/put_device.cocci
>
> Thus adjust jump targets to fix the exception handling for this
> function implementation.
>
> Fixes: 3933961682a30ae7d405cda344c040a129fea422 ("fsl/fman: Add FMan MAC driver")

Hello,

The information “State 	Rejected” is displayed for this patch
at the moment.
https://patchwork.ozlabs.org/patch/1192385/

How do you think about to clarify the development situation for
the affected software module a bit more?

Regards,
Markus

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

* Re: [PATCH 1/3] fsl/fman: Add missing put_device() calls in mac_probe()
@ 2019-11-10  9:15     ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2019-11-10  9:15 UTC (permalink / raw)
  To: netdev, David S. Miller; +Cc: LKML, kernel-janitors, Madalin Bucur, Wen Yang

> Generated by: scripts/coccinelle/free/put_device.cocci
>
> Thus adjust jump targets to fix the exception handling for this
> function implementation.
>
> Fixes: 3933961682a30ae7d405cda344c040a129fea422 ("fsl/fman: Add FMan MAC driver")

Hello,

The information “State 	Rejected” is displayed for this patch
at the moment.
https://patchwork.ozlabs.org/patch/1192385/

How do you think about to clarify the development situation for
the affected software module a bit more?

Regards,
Markus

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

end of thread, other threads:[~2019-11-10  9:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-09  8:55 [PATCH 0/3] FMan MAC: Improve exception handling in mac_probe() Markus Elfring
2019-11-09  8:55 ` Markus Elfring
2019-11-09  9:00 ` [PATCH 1/3] fsl/fman: Add missing put_device() calls " Markus Elfring
2019-11-09  9:00   ` Markus Elfring
2019-11-10  9:15   ` Markus Elfring
2019-11-10  9:15     ` Markus Elfring
2019-11-09  9:03 ` [PATCH 2/3] fsl/fman: Use common error handling code " Markus Elfring
2019-11-09  9:03   ` Markus Elfring
2019-11-09  9:03 ` Markus Elfring
2019-11-09  9:03   ` Markus Elfring
2019-11-09  9:06 ` [PATCH 3/3] fsl/fman: Return directly after a failed devm_kzalloc() " Markus Elfring
2019-11-09  9:06   ` Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.