net: faraday: ftmac100: convert to devm resource management
Subsystems (2)
PATCH 1/1 net: faraday: ftmac100: convert to devm resource management
Replace manual resource management with device-managed alternatives:
- alloc_etherdev() -> devm_alloc_etherdev()
- request_mem_region() + ioremap() -> devm_platform_ioremap_resource()
This simplifies error handling by removing manual cleanup in error paths and the remove function, and eliminates the risk of resource leaks.
--- drivers/net/ethernet/faraday/ftmac100.c | 47 +++++-------------------- 1 file changed, 9 insertions(+), 38 deletions(-)
drivers/net/ethernet/faraday/ftmac100.c +9 -38
@@ -49,7 +49,6 @@ struct ftmac100_descs { };struct ftmac100 { -struct resource *res;void __iomem *base;int irq;
@@ -1137,11 +1136,9 @@ static int ftmac100_probe(struct platform_device *pdev)return irq;/* setup net_device */ - netdev =alloc_etherdev (sizeof (*priv)); -if (!netdev) { - err = -ENOMEM ; - goto err_alloc_etherdev; - } + netdev =devm_alloc_etherdev (&pdev->dev,sizeof (*priv)); +if (!netdev) +return -ENOMEM ;SET_NETDEV_DEV (netdev, &pdev->dev); netdev->ethtool_ops = &ftmac100_ethtool_ops;
@@ -1150,7 +1147,7 @@ static int ftmac100_probe(struct platform_device *pdev) err =platform_get_ethdev_address (&pdev->dev, netdev);if (err == -EPROBE_DEFER ) - goto defer_get_mac; +return err;platform_set_drvdata (pdev, netdev);
@@ -1165,20 +1162,9 @@ static int ftmac100_probe(struct platform_device *pdev)netif_napi_add (netdev, &priv->napi, ftmac100_poll);/* map io memory */ - priv->res =request_mem_region (res->start,resource_size (res), -dev_name (&pdev->dev)); -if (!priv->res) { -dev_err (&pdev->dev,"Could not reserve memory region\n" ); - err = -ENOMEM ; - goto err_req_mem; - } - - priv->base =ioremap (res->start,resource_size (res)); -if (!priv->base) { -dev_err (&pdev->dev,"Failed to ioremap ethernet registers\n" ); - err = -EIO ; - goto err_ioremap; - } + priv->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base); priv->irq = irq;
@@ -1208,32 +1194,17 @@ static int ftmac100_probe(struct platform_device *pdev)return 0 ; err_register_netdev: -iounmap (priv->base); -err_ioremap: -release_resource (priv->res); -err_req_mem:netif_napi_del (&priv->napi); -defer_get_mac: -free_netdev (netdev); -err_alloc_etherdev:return err; }static void ftmac100_remove (struct platform_device *pdev) { -struct net_device *netdev; -struct ftmac100 *priv; - - netdev =platform_get_drvdata (pdev); - priv =netdev_priv (netdev); +struct net_device *netdev =platform_get_drvdata (pdev); +struct ftmac100 *priv =netdev_priv (netdev);unregister_netdev (netdev); - -iounmap (priv->base); -release_resource (priv->res); -netif_napi_del (&priv->napi); -free_netdev (netdev); }static const struct of_device_id ftmac100_of_ids[] = {
Signature · 1 line
2.54.0
Jakub Kicinski
maintainerQuoted 7 lines · On Tue, 16 Jun 2026 13:32:33 -0700 Jack Lee wrote:
Replace manual resource management with device-managed alternatives:
-alloc_etherdev()->devm_alloc_etherdev()
-request_mem_region()+ioremap()->devm_platform_ioremap_resource()This simplifies error handling by removing manual cleanup in error paths and the remove function, and eliminates the risk of resource leaks.
net-next is closed right now. Also:
Quoting documentation:
Clean-up patches
~~~~~~~~~~~~~~~~
Netdev discourages patches which perform simple clean-ups, which are not in the context of other work. For example:
* Addressing ``checkpatch.pl``, and other trivial coding style warnings
* Addressing :ref:Local variable ordering<rcs> issues
* Conversions to device-managed APIs (``devm_`` helpers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is because it is felt that the churn that such changes produce comes at a greater cost than the value of such clean-ups.
Conversely, spelling and grammar fixes are not discouraged.
See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#clean-up-patches
Signature · 1 line
pw-bot: reject