[OpenWrt-Devel] [PATCH 1/3] ramips: ethernet: Replace alloc_etherdev with devm variant

Paul Oranje por at oranjevos.nl
Fri Mar 15 05:45:09 EDT 2019



> Op 13 mrt. 2019, om 22:05 heeft Rosen Penev <rosenp at gmail.com> het volgende geschreven:
> 
> Allows simplifying the code slightly.
> 
> Also get rid of devm_iounmap as it is not necessary.
> 
> Tested on GnuBee PC1.
> 
> Signed-off-by: Rosen Penev <rosenp at gmail.com>
> ---
> .../net/ethernet/mediatek/mtk_eth_soc.c       | 38 ++++++-------------
> 1 file changed, 11 insertions(+), 27 deletions(-)
> 
> diff --git a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 2e0c8f94ca..d110787731 100644
> --- a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -1559,16 +1559,13 @@ static int fe_probe(struct platform_device *pdev)
> 		soc->reg_table = fe_reg_table;
> 
> 	fe_base = devm_ioremap_resource(&pdev->dev, res);
> -	if (IS_ERR(fe_base)) {
> -		err = -EADDRNOTAVAIL;
> -		goto err_out;
> -	}
> +	if (IS_ERR(fe_base))
> +		 return PTR_ERR(fe_base);
> 
> -	netdev = alloc_etherdev(sizeof(*priv));
> +	netdev = devm_alloc_etherdev(&pdev->dev, sizeof(*priv));
> 	if (!netdev) {
> -		dev_err(&pdev->dev, "alloc_etherdev failed\n");
> -		err = -ENOMEM;
> -		goto err_iounmap;
> +		dev_err(&pdev->dev, "devm_alloc_etherdev failed\n");
> +		return -ENOMEM;
> 	}
> 
> 	SET_NETDEV_DEV(netdev, &pdev->dev);
> @@ -1578,8 +1575,7 @@ static int fe_probe(struct platform_device *pdev)
> 	netdev->irq = platform_get_irq(pdev, 0);
> 	if (netdev->irq < 0) {
> 		dev_err(&pdev->dev, "no IRQ resource found\n");
> -		err = -ENXIO;
> -		goto err_free_dev;
> +		return -ENXIO;
> 	}
> 
> 	if (soc->init_data)
> @@ -1598,10 +1594,8 @@ static int fe_probe(struct platform_device *pdev)
> 	spin_lock_init(&priv->page_lock);
> 	if (fe_reg_table[FE_REG_FE_COUNTER_BASE]) {
> 		priv->hw_stats = kzalloc(sizeof(*priv->hw_stats), GFP_KERNEL);
> -		if (!priv->hw_stats) {
> -			err = -ENOMEM;
> -			goto err_free_dev;
> -		}
> +		if (!priv->hw_stats)
> +			return -ENOMEM;
> 		spin_lock_init(&priv->hw_stats->stats_lock);
> 	}
> 
> @@ -1610,15 +1604,13 @@ static int fe_probe(struct platform_device *pdev)
> 		priv->sysclk = clk_get_rate(sysclk);
> 	} else if ((priv->flags & FE_FLAG_CALIBRATE_CLK)) {
> 		dev_err(&pdev->dev, "this soc needs a clk for calibration\n");
> -		err = -ENXIO;
> -		goto err_free_dev;
> +		return -ENXIO;
> 	}
> 
> 	priv->switch_np = of_parse_phandle(pdev->dev.of_node, "mediatek,switch", 0);
> 	if ((priv->flags & FE_FLAG_HAS_SWITCH) && !priv->switch_np) {
> 		dev_err(&pdev->dev, "failed to read switch phandle\n");
> -		err = -ENODEV;
> -		goto err_free_dev;
> +		return -ENODEV;
> 	}
> 
> 	priv->netdev = netdev;
> @@ -1644,7 +1636,7 @@ static int fe_probe(struct platform_device *pdev)
> 	err = register_netdev(netdev);
> 	if (err) {
> 		dev_err(&pdev->dev, "error bringing up device\n");
> -		goto err_free_dev;
> +		return err;
> 	}
> 
> 	platform_set_drvdata(pdev, netdev);
> @@ -1653,13 +1645,6 @@ static int fe_probe(struct platform_device *pdev)
> 		   netdev->base_addr, netdev->irq);
> 
> 	return 0;
> -
> -err_free_dev:
> -	free_netdev(netdev);
> -err_iounmap:
> -	devm_iounmap(&pdev->dev, fe_base);
> -err_out:
> -	return err;
> }
> 
> static int fe_remove(struct platform_device *pdev)
> @@ -1673,7 +1658,6 @@ static int fe_remove(struct platform_device *pdev)
> 	cancel_work_sync(&priv->pending_work);
> 
> 	unregister_netdev(dev);
> -	free_netdev(dev);
> 	platform_set_drvdata(pdev, NULL);
> 
> 	return 0;
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel

For some of the other architectures similar patches have been submitted [0].
Would an approach using Coccinelle be feasible ?

LWN ran an article on Coccinelle where "devmification" wqs given as an example [1].
Anyhow, interesting read, also because it shows a few caveats with devmification irrespective of using Coccinelle.

Also LWN features an 2007 article on devm [2].

[0] https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=a4eef43a120d51bb5386730b820704e5cb5e1acf
[1] https://lwn.net/Articles/698724/
[2] https://lwn.net/Articles/222860/

Regards,
Paul


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list