2019-04-10 02:55:51

by Wen Yang

[permalink] [raw]
Subject: [PATCH v2] net: ethernet: ti: eliminate a bit of duplicate code in gbe_probe()

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 <[email protected]>
Reported-by: Markus Elfring <[email protected]>
Cc: Markus Elfring <[email protected]>
Cc: Wingman Kwok <[email protected]> (maintainer:TI NETCP ETHERNET DRIVER)
Cc: Murali Karicheri <[email protected]> (maintainer:TI NETCP ETHERNET DRIVER)
Cc: "David S. Miller" <[email protected]> (odd fixer:NETWORKING DRIVERS)
Cc: [email protected] (open list:TI NETCP ETHERNET DRIVER)
Cc: [email protected] (open list)
---
v2: Massaged changelog a bit

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


2019-04-10 09:10:51

by Markus Elfring

[permalink] [raw]
Subject: Re: [v2] ethernet: ti: eliminate a bit of duplicate code in gbe_probe()

> v2: Massaged changelog a bit

* How does this wording fit to the adjusted commit subject?

* Would it have been nicer to send this version as a direct reply
to the previous update suggestion?


> @@ -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");
> -

How do you think about to skip a bit of statements as a reaction for
such a null pointer?
https://elixir.bootlin.com/linux/v5.1-rc4/source/drivers/net/ethernet/ti/netcp_ethss.c#L3562


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

Can code like the following trigger corresponding software development concerns?

for_each_child_of_node(interfaces, interface) {

}
of_node_put(interfaces);

if (!gbe_dev->num_slaves)
dev_warn(dev, "No network interface configured\n");


Regards,
Markus