linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] net: xilinx: add a helper function for axienet_probe
@ 2019-04-09  5:48 Wen Yang
  2019-04-09  5:48 ` [PATCH 2/2] net: ethernet: ti: eliminated some duplicate code Wen Yang
  2019-04-09  6:36 ` [1/2] net: xilinx: add a helper function for axienet_probe Markus Elfring
  0 siblings, 2 replies; 4+ messages in thread
From: Wen Yang @ 2019-04-09  5:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: wang.yi59, Wen Yang, Anirudha Sarangi, John Linn,
	David S. Miller, Michal Simek, Markus Elfring, netdev,
	linux-arm-kernel

The "Find DMA Node, Map DMA Register, and Decode DMA IRQ" code snippets
in Axienet_Probe are independent. Tidy up axienet_probe a little by
factoring these out into a helper function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Reported-by: Markus Elfring <Markus.Elfring@web.de>
Cc: Anirudha Sarangi <anirudh@xilinx.com>
Cc: John Linn <John.Linn@xilinx.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Markus Elfring <Markus.Elfring@web.de>
Cc: netdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 69 +++++++++++++++--------
 1 file changed, 45 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index 4041c75..2d15897 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -1434,6 +1434,48 @@ static void axienet_dma_err_handler(unsigned long data)
 }
 
 /**
+ * axienet_dma_res_init - Initialize the DMA related resources of
+ *                        the axienet local structure.
+ * @lp: Pointer to axienet local structure
+ *
+ * Return: 0, on success
+ *	    Non-zero error value on failure.
+ *
+ * This function find the DMA node via pdev, map the DMA registers,
+ * and decode the DMA IRQs.
+ */
+static int axienet_dma_res_init(struct axienet_local *lp)
+{
+	struct resource dmares;
+	struct device_node *np;
+	int ret;
+
+	np = of_parse_phandle(lp->dev->of_node, "axistream-connected", 0);
+	if (!np) {
+		dev_err(lp->dev, "could not find DMA node\n");
+		ret = -ENODEV;
+		return ret;
+	}
+	ret = of_address_to_resource(np, 0, &dmares);
+	if (ret) {
+		dev_err(lp->dev, "unable to get DMA resource\n");
+		goto put_node;
+	}
+	lp->dma_regs = devm_ioremap_resource(lp->dev, &dmares);
+	if (IS_ERR(lp->dma_regs)) {
+		dev_err(lp->dev, "could not map DMA regs\n");
+		ret = PTR_ERR(lp->dma_regs);
+		goto put_node;
+	}
+	lp->rx_irq = irq_of_parse_and_map(np, 1);
+	lp->tx_irq = irq_of_parse_and_map(np, 0);
+
+put_node:
+	of_node_put(np);
+	return ret;
+}
+
+/**
  * axienet_probe - Axi Ethernet probe function.
  * @pdev:	Pointer to platform device structure.
  *
@@ -1448,11 +1490,10 @@ static void axienet_dma_err_handler(unsigned long data)
 static int axienet_probe(struct platform_device *pdev)
 {
 	int ret;
-	struct device_node *np;
 	struct axienet_local *lp;
 	struct net_device *ndev;
 	const void *mac_addr;
-	struct resource *ethres, dmares;
+	struct resource *ethres;
 	u32 value;
 
 	ndev = alloc_etherdev(sizeof(*lp));
@@ -1565,29 +1606,9 @@ static int axienet_probe(struct platform_device *pdev)
 		}
 	}
 
-	/* Find the DMA node, map the DMA registers, and decode the DMA IRQs */
-	np = of_parse_phandle(pdev->dev.of_node, "axistream-connected", 0);
-	if (!np) {
-		dev_err(&pdev->dev, "could not find DMA node\n");
-		ret = -ENODEV;
-		goto free_netdev;
-	}
-	ret = of_address_to_resource(np, 0, &dmares);
-	if (ret) {
-		dev_err(&pdev->dev, "unable to get DMA resource\n");
-		of_node_put(np);
-		goto free_netdev;
-	}
-	lp->dma_regs = devm_ioremap_resource(&pdev->dev, &dmares);
-	if (IS_ERR(lp->dma_regs)) {
-		dev_err(&pdev->dev, "could not map DMA regs\n");
-		ret = PTR_ERR(lp->dma_regs);
-		of_node_put(np);
+	ret = axienet_dma_res_init(lp);
+	if (ret)
 		goto free_netdev;
-	}
-	lp->rx_irq = irq_of_parse_and_map(np, 1);
-	lp->tx_irq = irq_of_parse_and_map(np, 0);
-	of_node_put(np);
 	if ((lp->rx_irq <= 0) || (lp->tx_irq <= 0)) {
 		dev_err(&pdev->dev, "could not determine irqs\n");
 		ret = -ENOMEM;
-- 
2.9.5


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

* [PATCH 2/2] net: ethernet: ti: eliminated some duplicate code.
  2019-04-09  5:48 [PATCH 1/2] net: xilinx: add a helper function for axienet_probe Wen Yang
@ 2019-04-09  5:48 ` Wen Yang
  2019-04-09  7:30   ` [2/2] " Markus Elfring
  2019-04-09  6:36 ` [1/2] net: xilinx: add a helper function for axienet_probe Markus Elfring
  1 sibling, 1 reply; 4+ messages in thread
From: Wen Yang @ 2019-04-09  5:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: wang.yi59, Wen Yang, Markus Elfring, Wingman Kwok,
	Murali Karicheri, David S. Miller,
	open list:TI NETCP ETHERNET DRIVER

Put the code that obtains device_node and the code that
uses it tightly together to remove duplicate resource
cleanup statements between them.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Reported-by: Markus Elfring <Markus.Elfring@web.de>
Cc: Markus Elfring <Markus.Elfring@web.de>
Cc: Wingman Kwok <w-kwok2@ti.com> (maintainer:TI NETCP ETHERNET DRIVER)
Cc: Murali Karicheri <m-karicheri2@ti.com> (maintainer:TI NETCP ETHERNET DRIVER)
Cc: "David S. Miller" <davem@davemloft.net> (odd fixer:NETWORKING DRIVERS)
Cc: netdev@vger.kernel.org (open list:TI NETCP ETHERNET DRIVER)
Cc: linux-kernel@vger.kernel.org (open list)
---
 drivers/net/ethernet/ti/netcp_ethss.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c
index 0a920c5..748116a 100644
--- a/drivers/net/ethernet/ti/netcp_ethss.c
+++ b/drivers/net/ethernet/ti/netcp_ethss.c
@@ -3651,22 +3651,18 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
 	if (ret)
 		return ret;
 
-	interfaces = of_get_child_by_name(node, "interfaces");
-	if (!interfaces)
-		dev_err(dev, "could not find interfaces\n");
-
 	ret = netcp_txpipe_init(&gbe_dev->tx_pipe, netcp_device,
 				gbe_dev->dma_chan_name, gbe_dev->tx_queue_id);
-	if (ret) {
-		of_node_put(interfaces);
+	if (ret)
 		return ret;
-	}
 
 	ret = netcp_txpipe_open(&gbe_dev->tx_pipe);
-	if (ret) {
-		of_node_put(interfaces);
+	if (ret)
 		return ret;
-	}
+
+	interfaces = of_get_child_by_name(node, "interfaces");
+	if (!interfaces)
+		dev_err(dev, "could not find interfaces\n");
 
 	/* Create network interfaces */
 	INIT_LIST_HEAD(&gbe_dev->gbe_intf_head);
-- 
2.9.5


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

* Re: [1/2] net: xilinx: add a helper function for axienet_probe
  2019-04-09  5:48 [PATCH 1/2] net: xilinx: add a helper function for axienet_probe Wen Yang
  2019-04-09  5:48 ` [PATCH 2/2] net: ethernet: ti: eliminated some duplicate code Wen Yang
@ 2019-04-09  6:36 ` Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-04-09  6:36 UTC (permalink / raw)
  To: Wen Yang, netdev, linux-arm-kernel
  Cc: linux-kernel, Yi Wang, Anirudha Sarangi, John Linn,
	David S. Miller, Michal Simek

> The "Find DMA Node, Map DMA Register, and Decode DMA IRQ" code snippets
> in Axienet_Probe are independent. Tidy up axienet_probe a little by
> factoring these out into a helper function.

Would the following wording be more appropriate for the commit description?


in axienet_probe() are independent.
Tidy this function implementation a little up by factoring these calls out
into a helper function.


Regards,
Markus

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

* Re: [2/2] ethernet: ti: eliminated some duplicate code.
  2019-04-09  5:48 ` [PATCH 2/2] net: ethernet: ti: eliminated some duplicate code Wen Yang
@ 2019-04-09  7:30   ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-04-09  7:30 UTC (permalink / raw)
  To: Wen Yang, netdev
  Cc: linux-kernel, Yi Wang, Wingman Kwok, Murali Karicheri, David S. Miller

> Put the code that obtains device_node and the code that
> uses it tightly together to remove duplicate resource
> cleanup statements between them.

1. Would the wording “ethernet: ti: eliminate a bit of duplicate code in gbe_probe()”
   be more appropriate for the commit subject?

2. I find that such a change can be provided also without combining
   it into a patch series with only two update steps.
   Otherwise: Why did you omit the cover letter for the updates
              by this small patch series?


> @@ -3651,22 +3651,18 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
>  	if (ret)
>  		return ret;
>
> -	interfaces = of_get_child_by_name(node, "interfaces");
> -	if (!interfaces)
> -		dev_err(dev, "could not find interfaces\n");
> -
>  	ret = netcp_txpipe_init(&gbe_dev->tx_pipe, netcp_device,
>  				gbe_dev->dma_chan_name, gbe_dev->tx_queue_id);
> -	if (ret) {
> -		of_node_put(interfaces);
> +	if (ret)
>  		return ret;
> -	}
>
>  	ret = netcp_txpipe_open(&gbe_dev->tx_pipe);
> -	if (ret) {
> -		of_node_put(interfaces);
> +	if (ret)
>  		return ret;
> -	}
> +
> +	interfaces = of_get_child_by_name(node, "interfaces");
> +	if (!interfaces)
> +		dev_err(dev, "could not find interfaces\n");

3. Can this error message trigger any further software development considerations
   for the desired exception handling?


>
>  	/* Create network interfaces */
>  	INIT_LIST_HEAD(&gbe_dev->gbe_intf_head);


Regards,
Markus

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

end of thread, other threads:[~2019-04-09  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-09  5:48 [PATCH 1/2] net: xilinx: add a helper function for axienet_probe Wen Yang
2019-04-09  5:48 ` [PATCH 2/2] net: ethernet: ti: eliminated some duplicate code Wen Yang
2019-04-09  7:30   ` [2/2] " Markus Elfring
2019-04-09  6:36 ` [1/2] net: xilinx: add a helper function for axienet_probe Markus Elfring

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