Skip to contentSkip to conversation

First bunch of cleanups

PATCH Superseded Moritz Fischer 1 participant 5 messages Sep 14, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover First bunch of cleanups

This series is the first bunch of minor cleanups for the de2104x driver to make it look and behave more like a modern driver.

These changes replace some of the non-devres versions with devres versions of functions to simplify the error paths.

Next up after this will be the ioremap part.

Moritz Fischer (3):
net: dec: tulip: de2104x: Replace alloc_etherdev by
devm_alloc_etherdev
net: dec: tulip: de2104x: Replace pci_enable_device with devres
version
net: dec: tulip: de2104x: Replace kmemdup() with devm_kmempdup()

 drivers/net/ethernet/dec/tulip/de2104x.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
Signature · 1 line
2.28.0
#2 lore raw

PATCH 2/3 net: dec: tulip: de2104x: Replace pci_enable_device with devres version

Replace pci_enable_device() with its devres counterpart pcim_enable_device().

---
 drivers/net/ethernet/dec/tulip/de2104x.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/dec/tulip/de2104x.c +2 -5
index 9bcfc82b71d1..e4189c45c2ba 100644
@@ -2009,14 +2009,14 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	netif_carrier_off(dev);
 
 	/* wake up device, assign resources */
-	rc = pci_enable_device(pdev);
+	rc = pcim_enable_device(pdev);
 	if (rc)
 		return rc;
 
 	/* reserve PCI resources to ensure driver atomicity */
 	rc = pci_request_regions(pdev, DRV_NAME);
 	if (rc)
-		goto err_out_disable;
+		return rc;
 
 	/* check for invalid IRQ value */
 	if (pdev->irq < 2) {
@@ -2096,8 +2096,6 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	iounmap(regs);
 err_out_res:
 	pci_release_regions(pdev);
-err_out_disable:
-	pci_disable_device(pdev);
 	return rc;
 }
 
@@ -2111,7 +2109,6 @@ static void de_remove_one(struct pci_dev *pdev)
 	kfree(de->ee_data);
 	iounmap(de->regs);
 	pci_release_regions(pdev);
-	pci_disable_device(pdev);
 }
 
 #ifdef CONFIG_PM
Signature · 1 line
2.28.0
#4 lore raw

PATCH 3/3 net: dec: tulip: de2104x: Replace kmemdup() with devm_kmempdup()

In reply to Moritz Fischer

Replace an instance of kmemdup() with the devres counted version instead.

---
 drivers/net/ethernet/dec/tulip/de2104x.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/dec/tulip/de2104x.c +2 -3
index e4189c45c2ba..4933799c6a15 100644
@@ -1940,7 +1940,8 @@ static void de21041_get_srom_info(struct de_private *de)
 			de->media[i].csr15 = t21041_csr15[i];
 	}
 
-	de->ee_data = kmemdup(&ee_data[0], DE_EEPROM_SIZE, GFP_KERNEL);
+	de->ee_data = devm_kmemdup(&de->pdev->dev, &ee_data[0], DE_EEPROM_SIZE,
+				   GFP_KERNEL);
 
 	return;
 
@@ -2092,7 +2093,6 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	return 0;
 
 err_out_iomap:
-	kfree(de->ee_data);
 	iounmap(regs);
 err_out_res:
 	pci_release_regions(pdev);
@@ -2106,7 +2106,6 @@ static void de_remove_one(struct pci_dev *pdev)
 
 	BUG_ON(!dev);
 	unregister_netdev(dev);
-	kfree(de->ee_data);
 	iounmap(de->regs);
 	pci_release_regions(pdev);
 }
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/3 net: dec: tulip: de2104x: Replace alloc_etherdev by devm_alloc_etherdev

In reply to Moritz Fischer

Replace devm_alloc_etherdev() with its devres version.

---
 drivers/net/ethernet/dec/tulip/de2104x.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/dec/tulip/de2104x.c +2 -5
index 42b798a3fad4..9bcfc82b71d1 100644
@@ -1986,7 +1986,7 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #endif
 
 	/* allocate a new ethernet device structure, and fill in defaults */
-	dev = alloc_etherdev(sizeof(struct de_private));
+	dev = devm_alloc_etherdev(&pdev->dev, sizeof(struct de_private));
 	if (!dev)
 		return -ENOMEM;
 
@@ -2011,7 +2011,7 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	/* wake up device, assign resources */
 	rc = pci_enable_device(pdev);
 	if (rc)
-		goto err_out_free;
+		return rc;
 
 	/* reserve PCI resources to ensure driver atomicity */
 	rc = pci_request_regions(pdev, DRV_NAME);
@@ -2098,8 +2098,6 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	pci_release_regions(pdev);
 err_out_disable:
 	pci_disable_device(pdev);
-err_out_free:
-	free_netdev(dev);
 	return rc;
 }
 
@@ -2114,7 +2112,6 @@ static void de_remove_one(struct pci_dev *pdev)
 	iounmap(de->regs);
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
-	free_netdev(dev);
 }
 
 #ifdef CONFIG_PM
Signature · 1 line
2.28.0
#3 lore raw

Re: [PATCH net-next 2/3] net: dec: tulip: de2104x: Replace pci_enable_device with devres version

In reply to Moritz Fischer
Quoted 49 lines · Moritz Fischer

Replace pci_enable_device() with its devres counterpart pcim_enable_device().

---
 drivers/net/ethernet/dec/tulip/de2104x.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/dec/tulip/de2104x.c +2 -5
index 9bcfc82b71d1..e4189c45c2ba 100644
@@ -2009,14 +2009,14 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	netif_carrier_off(dev);
 
 	/* wake up device, assign resources */
-	rc = pci_enable_device(pdev);
+	rc = pcim_enable_device(pdev);
 	if (rc)
 		return rc;
 
 	/* reserve PCI resources to ensure driver atomicity */
 	rc = pci_request_regions(pdev, DRV_NAME);
 	if (rc)
-		goto err_out_disable;
+		return rc;
 
 	/* check for invalid IRQ value */
 	if (pdev->irq < 2) {
@@ -2096,8 +2096,6 @@ static int de_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	iounmap(regs);
 err_out_res:
 	pci_release_regions(pdev);
-err_out_disable:
-	pci_disable_device(pdev);
 	return rc;
 }
 
@@ -2111,7 +2109,6 @@ static void de_remove_one(struct pci_dev *pdev)
 	kfree(de->ee_data);
 	iounmap(de->regs);
 	pci_release_regions(pdev);
-	pci_disable_device(pdev);
 }
 
 #ifdef CONFIG_PM
Signature · 1 line
2.28.0

Ugh, sorry for the noise, I missed the instances in the suspend/resume. Let me resend a v2 of this ...

Thanks,
Moritz