From ba24b94e0b84840d6396d57672e1a33032ebe146 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 14 Aug 2024 17:50:20 -0700 Subject: [PATCH] ramips: use more devm in mtk_eth_soc These got added to the kernel after this driver was written. Signed-off-by: Rosen Penev Link: https://github.com/openwrt/openwrt/pull/16415 Signed-off-by: Hauke Mehrtens --- .../drivers/net/ethernet/ralink/mtk_eth_soc.c | 49 ++++++------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/target/linux/ramips/files/drivers/net/ethernet/ralink/mtk_eth_soc.c b/target/linux/ramips/files/drivers/net/ethernet/ralink/mtk_eth_soc.c index c7e074aaa5..893198d826 100644 --- a/target/linux/ramips/files/drivers/net/ethernet/ralink/mtk_eth_soc.c +++ b/target/linux/ramips/files/drivers/net/ethernet/ralink/mtk_eth_soc.c @@ -1522,7 +1522,6 @@ static void fe_pending_work(struct work_struct *work) static int fe_probe(struct platform_device *pdev) { - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); const struct of_device_id *match; struct fe_soc_data *soc; struct net_device *netdev; @@ -1542,17 +1541,14 @@ static int fe_probe(struct platform_device *pdev) else soc->reg_table = fe_reg_table; - fe_base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(fe_base)) { - err = -EADDRNOTAVAIL; - goto err_out; - } + fe_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(fe_base)) + return PTR_ERR(fe_base); - netdev = alloc_etherdev(sizeof(*priv)); + netdev = devm_alloc_etherdev_mqs(&pdev->dev, sizeof(*priv), 4, 4); if (!netdev) { dev_err(&pdev->dev, "alloc_etherdev failed\n"); - err = -ENOMEM; - goto err_iounmap; + return -ENOMEM; } 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); if (netdev->irq < 0) { dev_err(&pdev->dev, "no IRQ resource found\n"); - err = -ENXIO; - goto err_free_dev; + return -ENXIO; } priv = netdev_priv(netdev); 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)) { 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) @@ -1589,11 +1584,9 @@ static int fe_probe(struct platform_device *pdev) netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; 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; - } + priv->hw_stats = devm_kzalloc(&pdev->dev, sizeof(*priv->hw_stats), GFP_KERNEL); + if (!priv->hw_stats) + return -ENOMEM; spin_lock_init(&priv->hw_stats->stats_lock); 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); } 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; @@ -1633,10 +1624,10 @@ static int fe_probe(struct platform_device *pdev) netif_napi_add_weight(netdev, &priv->rx_napi, fe_poll, napi_weight); fe_set_ethtool_ops(netdev); - err = register_netdev(netdev); + err = devm_register_netdev(&pdev->dev, netdev); if (err) { dev_err(&pdev->dev, "error bringing up device\n"); - goto err_free_dev; + return err; } platform_set_drvdata(pdev, netdev); @@ -1645,13 +1636,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) @@ -1660,12 +1644,9 @@ static int fe_remove(struct platform_device *pdev) struct fe_priv *priv = netdev_priv(dev); netif_napi_del(&priv->rx_napi); - kfree(priv->hw_stats); cancel_work_sync(&priv->pending_work); - unregister_netdev(dev); - free_netdev(dev); platform_set_drvdata(pdev, NULL); return 0; -- 2.30.2