ramips: use more devm in mtk_eth_soc

These got added to the kernel after this driver was written.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16415
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
Rosen Penev 2024-08-14 17:50:20 -07:00 committed by Hauke Mehrtens
parent 65ed475450
commit ba24b94e0b

View File

@ -1522,7 +1522,6 @@ static void fe_pending_work(struct work_struct *work)
static int fe_probe(struct platform_device *pdev) static int fe_probe(struct platform_device *pdev)
{ {
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
const struct of_device_id *match; const struct of_device_id *match;
struct fe_soc_data *soc; struct fe_soc_data *soc;
struct net_device *netdev; struct net_device *netdev;
@ -1542,17 +1541,14 @@ static int fe_probe(struct platform_device *pdev)
else else
soc->reg_table = fe_reg_table; soc->reg_table = fe_reg_table;
fe_base = devm_ioremap_resource(&pdev->dev, res); fe_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(fe_base)) { if (IS_ERR(fe_base))
err = -EADDRNOTAVAIL; return PTR_ERR(fe_base);
goto err_out;
}
netdev = alloc_etherdev(sizeof(*priv)); netdev = devm_alloc_etherdev_mqs(&pdev->dev, sizeof(*priv), 4, 4);
if (!netdev) { if (!netdev) {
dev_err(&pdev->dev, "alloc_etherdev failed\n"); dev_err(&pdev->dev, "alloc_etherdev failed\n");
err = -ENOMEM; return -ENOMEM;
goto err_iounmap;
} }
SET_NETDEV_DEV(netdev, &pdev->dev); SET_NETDEV_DEV(netdev, &pdev->dev);
@ -1562,16 +1558,15 @@ static int fe_probe(struct platform_device *pdev)
netdev->irq = platform_get_irq(pdev, 0); netdev->irq = platform_get_irq(pdev, 0);
if (netdev->irq < 0) { if (netdev->irq < 0) {
dev_err(&pdev->dev, "no IRQ resource found\n"); dev_err(&pdev->dev, "no IRQ resource found\n");
err = -ENXIO; return -ENXIO;
goto err_free_dev;
} }
priv = netdev_priv(netdev); priv = netdev_priv(netdev);
spin_lock_init(&priv->page_lock); spin_lock_init(&priv->page_lock);
priv->resets = devm_reset_control_array_get_exclusive(&pdev->dev); priv->resets = devm_reset_control_array_get_optional_exclusive(&pdev->dev);
if (IS_ERR(priv->resets)) { if (IS_ERR(priv->resets)) {
dev_err(&pdev->dev, "Failed to get resets for FE and ESW cores: %pe\n", priv->resets); dev_err(&pdev->dev, "Failed to get resets for FE and ESW cores: %pe\n", priv->resets);
priv->resets = NULL; return PTR_ERR(priv->resets);
} }
if (soc->init_data) if (soc->init_data)
@ -1589,11 +1584,9 @@ static int fe_probe(struct platform_device *pdev)
netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
if (fe_reg_table[FE_REG_FE_COUNTER_BASE]) { if (fe_reg_table[FE_REG_FE_COUNTER_BASE]) {
priv->hw_stats = kzalloc(sizeof(*priv->hw_stats), GFP_KERNEL); priv->hw_stats = devm_kzalloc(&pdev->dev, sizeof(*priv->hw_stats), GFP_KERNEL);
if (!priv->hw_stats) { if (!priv->hw_stats)
err = -ENOMEM; return -ENOMEM;
goto err_free_dev;
}
spin_lock_init(&priv->hw_stats->stats_lock); spin_lock_init(&priv->hw_stats->stats_lock);
u64_stats_init(&priv->hw_stats->syncp); u64_stats_init(&priv->hw_stats->syncp);
} }
@ -1603,15 +1596,13 @@ static int fe_probe(struct platform_device *pdev)
priv->sysclk = clk_get_rate(sysclk); priv->sysclk = clk_get_rate(sysclk);
} else if ((priv->flags & FE_FLAG_CALIBRATE_CLK)) { } else if ((priv->flags & FE_FLAG_CALIBRATE_CLK)) {
dev_err(&pdev->dev, "this soc needs a clk for calibration\n"); dev_err(&pdev->dev, "this soc needs a clk for calibration\n");
err = -ENXIO; return -ENXIO;
goto err_free_dev;
} }
priv->switch_np = of_parse_phandle(pdev->dev.of_node, "mediatek,switch", 0); priv->switch_np = of_parse_phandle(pdev->dev.of_node, "mediatek,switch", 0);
if ((priv->flags & FE_FLAG_HAS_SWITCH) && !priv->switch_np) { if ((priv->flags & FE_FLAG_HAS_SWITCH) && !priv->switch_np) {
dev_err(&pdev->dev, "failed to read switch phandle\n"); dev_err(&pdev->dev, "failed to read switch phandle\n");
err = -ENODEV; return -ENODEV;
goto err_free_dev;
} }
priv->netdev = netdev; priv->netdev = netdev;
@ -1633,10 +1624,10 @@ static int fe_probe(struct platform_device *pdev)
netif_napi_add_weight(netdev, &priv->rx_napi, fe_poll, napi_weight); netif_napi_add_weight(netdev, &priv->rx_napi, fe_poll, napi_weight);
fe_set_ethtool_ops(netdev); fe_set_ethtool_ops(netdev);
err = register_netdev(netdev); err = devm_register_netdev(&pdev->dev, netdev);
if (err) { if (err) {
dev_err(&pdev->dev, "error bringing up device\n"); dev_err(&pdev->dev, "error bringing up device\n");
goto err_free_dev; return err;
} }
platform_set_drvdata(pdev, netdev); platform_set_drvdata(pdev, netdev);
@ -1645,13 +1636,6 @@ static int fe_probe(struct platform_device *pdev)
netdev->base_addr, netdev->irq); netdev->base_addr, netdev->irq);
return 0; 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) static int fe_remove(struct platform_device *pdev)
@ -1660,12 +1644,9 @@ static int fe_remove(struct platform_device *pdev)
struct fe_priv *priv = netdev_priv(dev); struct fe_priv *priv = netdev_priv(dev);
netif_napi_del(&priv->rx_napi); netif_napi_del(&priv->rx_napi);
kfree(priv->hw_stats);
cancel_work_sync(&priv->pending_work); cancel_work_sync(&priv->pending_work);
unregister_netdev(dev);
free_netdev(dev);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
return 0; return 0;