Skip to contentSkip to conversation

net: ethernet: litex: minor improvment for the codebase

PATCH Superseded Inochi Amaoto 2 participants 5 messages Jan 19 – Jan 21

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: ethernet: litex: minor improvment for the codebase

Improve the litex code for using the device managed function to register netdev and replace all the "pdev->dev" with dev pointer instead.

Change from v1:
- https://lore.kernel.org/netdev/[email protected]/
1. separate the original patch into two patches.

Inochi Amaoto (2):
net: ethernet: litex: use devm_register_netdev() to register netdev
net: ethernet: litex: use device pointer to simplify code.

 drivers/net/ethernet/litex/litex_liteeth.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

--
2.52.0

#1 lore raw

PATCH v2 1/2 net: ethernet: litex: use devm_register_netdev() to register netdev

Use devm_register_netdev to avoid unnecessary remove() callback in platform_driver structure.

---
 drivers/net/ethernet/litex/litex_liteeth.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/net/ethernet/litex/litex_liteeth.c +2 -9
index 829a4b828f8e..67ad1058c2ab 100644
@@ -232,6 +232,7 @@ static void liteeth_setup_slots(struct liteeth *priv)
 
 static int liteeth_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct net_device *netdev;
 	void __iomem *buf_base;
 	struct liteeth *priv;
@@ -282,7 +283,7 @@ static int liteeth_probe(struct platform_device *pdev)
 
 	netdev->netdev_ops = &liteeth_netdev_ops;
 
-	err = register_netdev(netdev);
+	err = devm_register_netdev(dev, netdev);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to register netdev %d\n", err);
 		return err;
@@ -294,13 +295,6 @@ static int liteeth_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void liteeth_remove(struct platform_device *pdev)
-{
-	struct net_device *netdev = platform_get_drvdata(pdev);
-
-	unregister_netdev(netdev);
-}
-
 static const struct of_device_id liteeth_of_match[] = {
 	{ .compatible = "litex,liteeth" },
 	{ }
@@ -309,7 +303,6 @@ MODULE_DEVICE_TABLE(of, liteeth_of_match);
 
 static struct platform_driver liteeth_driver = {
 	.probe = liteeth_probe,
-	.remove = liteeth_remove,
 	.driver = {
 		.name = DRV_NAME,
 		.of_match_table = liteeth_of_match,
Signature · 1 line
2.52.0
#3 lore raw

PATCH v2 2/2 net: ethernet: litex: use device pointer to simplify code.

In reply to Inochi Amaoto

As there is already a device pointer in the probe function, replace all "&pdev->dev" pattern with this predefined device pointer.

---
 drivers/net/ethernet/litex/litex_liteeth.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/net/ethernet/litex/litex_liteeth.c +5 -6
index 67ad1058c2ab..670f2a406d7d 100644
@@ -238,7 +238,7 @@ static int liteeth_probe(struct platform_device *pdev)
 	struct liteeth *priv;
 	int irq, err;
 
-	netdev = devm_alloc_etherdev(&pdev->dev, sizeof(*priv));
+	netdev = devm_alloc_etherdev(dev, sizeof(*priv));
 	if (!netdev)
 		return -ENOMEM;
 
@@ -247,10 +247,9 @@ static int liteeth_probe(struct platform_device *pdev)
 
 	priv = netdev_priv(netdev);
 	priv->netdev = netdev;
-	priv->dev = &pdev->dev;
+	priv->dev = dev;
 
-	netdev->tstats = devm_netdev_alloc_pcpu_stats(&pdev->dev,
-						      struct pcpu_sw_netstats);
+	netdev->tstats = devm_netdev_alloc_pcpu_stats(dev, struct pcpu_sw_netstats);
 	if (!netdev->tstats)
 		return -ENOMEM;
 
@@ -277,7 +276,7 @@ static int liteeth_probe(struct platform_device *pdev)
 	priv->tx_base = buf_base + priv->num_rx_slots * priv->slot_size;
 	priv->tx_slot = 0;
 
-	err = of_get_ethdev_address(pdev->dev.of_node, netdev);
+	err = of_get_ethdev_address(dev->of_node, netdev);
 	if (err)
 		eth_hw_addr_random(netdev);
 
@@ -285,7 +284,7 @@ static int liteeth_probe(struct platform_device *pdev)
 
 	err = devm_register_netdev(dev, netdev);
 	if (err) {
-		dev_err(&pdev->dev, "Failed to register netdev %d\n", err);
+		dev_err(dev, "Failed to register netdev %d\n", err);
 		return err;
 	}
 
Signature · 1 line
2.52.0
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH net-next v2 2/2] net: ethernet: litex: use device pointer to simplify code.

In reply to Inochi Amaoto

drivers/net/ethernet/litex/litex_liteeth.c static int liteeth_probe(struct platform_device *pdev) · line 252

Quoted 3 lines
drivers/net/ethernet/litex/litex_liteeth.c +1 -2
-	netdev->tstats = devm_netdev_alloc_pcpu_stats(&pdev->dev,
-						      struct pcpu_sw_netstats);
+	netdev->tstats = devm_netdev_alloc_pcpu_stats(dev, struct pcpu_sw_netstats);

Is that longer than 80 characters? netdev keeps with the lower limit.

Otherwise

Andrew