diff mbox series

[PATCHv2,net-next,03/10] net: lantiq_etop: use devm for register_netdev

Message ID 20241001184607.193461-4-rosenp@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: lantiq_etop: some cleanups | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 12 this patch: 12
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 35 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Rosen Penev Oct. 1, 2024, 6:46 p.m. UTC
This is the last to be created and so must be the first to be freed.
Simpler to avoid by using devm.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>
---
 drivers/net/ethernet/lantiq_etop.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Andrew Lunn Oct. 1, 2024, 10:48 p.m. UTC | #1
On Tue, Oct 01, 2024 at 11:46:00AM -0700, Rosen Penev wrote:
> This is the last to be created and so must be the first to be freed.
> Simpler to avoid by using devm.

Actually, devm does not enforce that. All it enforces is that
resources controlled via devm are released in reverse order. Things
not using devm will be release first by explicit code.

The only reason devm is safe is that the core ensures the interface is
closed. So the order probably does not matter.

    Andrew

---
pw-bot: cr
diff mbox series

Patch

diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index de4f75ce8d9d..988f204fd89c 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -587,7 +587,7 @@  ltq_etop_init(struct net_device *dev)
 
 	err = ltq_etop_set_mac_address(dev, &mac);
 	if (err)
-		goto err_netdev;
+		goto err_hw;
 
 	/* Set addr_assign_type here, ltq_etop_set_mac_address would reset it. */
 	if (random_mac)
@@ -596,11 +596,9 @@  ltq_etop_init(struct net_device *dev)
 	ltq_etop_set_multicast_list(dev);
 	err = ltq_etop_mdio_init(dev);
 	if (err)
-		goto err_netdev;
+		goto err_hw;
 	return 0;
 
-err_netdev:
-	unregister_netdev(dev);
 err_hw:
 	ltq_etop_hw_exit(dev);
 	return err;
@@ -709,7 +707,7 @@  ltq_etop_probe(struct platform_device *pdev)
 		priv->ch[i].netdev = dev;
 	}
 
-	err = register_netdev(dev);
+	err = devm_register_netdev(&pdev->dev, dev);
 	if (err)
 		goto err_out;
 
@@ -728,7 +726,6 @@  static void ltq_etop_remove(struct platform_device *pdev)
 		netif_tx_stop_all_queues(dev);
 		ltq_etop_hw_exit(dev);
 		ltq_etop_mdio_cleanup(dev);
-		unregister_netdev(dev);
 	}
 }