realtek: use more devm
Simplifies probe slightly. Signed-off-by: Rosen Penev <rosenp@gmail.com> Link: https://github.com/openwrt/openwrt/pull/16650 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
parent
e8d8cadd24
commit
96fa9ee3da
1 changed files with 15 additions and 45 deletions
|
@ -2326,7 +2326,7 @@ static int rtl838x_mdio_init(struct rtl838x_eth_priv *priv)
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%pOFn", mii_np);
|
snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%pOFn", mii_np);
|
||||||
ret = of_mdiobus_register(priv->mii_bus, mii_np);
|
ret = devm_of_mdiobus_register(&priv->pdev->dev, priv->mii_bus, mii_np);
|
||||||
|
|
||||||
err_put_node:
|
err_put_node:
|
||||||
of_node_put(mii_np);
|
of_node_put(mii_np);
|
||||||
|
@ -2334,18 +2334,6 @@ err_put_node:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtl838x_mdio_remove(struct rtl838x_eth_priv *priv)
|
|
||||||
{
|
|
||||||
pr_debug("%s called\n", __func__);
|
|
||||||
if (!priv->mii_bus)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
mdiobus_unregister(priv->mii_bus);
|
|
||||||
mdiobus_free(priv->mii_bus);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static netdev_features_t rtl838x_fix_features(struct net_device *dev,
|
static netdev_features_t rtl838x_fix_features(struct net_device *dev,
|
||||||
netdev_features_t features)
|
netdev_features_t features)
|
||||||
{
|
{
|
||||||
|
@ -2489,11 +2477,9 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
rxringlen = MAX_ENTRIES / rxrings;
|
rxringlen = MAX_ENTRIES / rxrings;
|
||||||
rxringlen = rxringlen > MAX_RXLEN ? MAX_RXLEN : rxringlen;
|
rxringlen = rxringlen > MAX_RXLEN ? MAX_RXLEN : rxringlen;
|
||||||
|
|
||||||
dev = alloc_etherdev_mqs(sizeof(struct rtl838x_eth_priv), TXRINGS, rxrings);
|
dev = devm_alloc_etherdev_mqs(&pdev->dev, sizeof(struct rtl838x_eth_priv), TXRINGS, rxrings);
|
||||||
if (!dev) {
|
if (!dev)
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_free;
|
|
||||||
}
|
|
||||||
SET_NETDEV_DEV(dev, &pdev->dev);
|
SET_NETDEV_DEV(dev, &pdev->dev);
|
||||||
priv = netdev_priv(dev);
|
priv = netdev_priv(dev);
|
||||||
|
|
||||||
|
@ -2504,16 +2490,14 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
resource_size(res), res->name);
|
resource_size(res), res->name);
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
dev_err(&pdev->dev, "cannot request memory space\n");
|
dev_err(&pdev->dev, "cannot request memory space\n");
|
||||||
err = -ENXIO;
|
return -ENXIO;
|
||||||
goto err_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->mem_start = mem->start;
|
dev->mem_start = mem->start;
|
||||||
dev->mem_end = mem->end;
|
dev->mem_end = mem->end;
|
||||||
} else {
|
} else {
|
||||||
dev_err(&pdev->dev, "cannot request IO resource\n");
|
dev_err(&pdev->dev, "cannot request IO resource\n");
|
||||||
err = -ENXIO;
|
return -ENXIO;
|
||||||
goto err_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate buffer memory */
|
/* Allocate buffer memory */
|
||||||
|
@ -2522,8 +2506,7 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
(void *)&dev->mem_start, GFP_KERNEL);
|
(void *)&dev->mem_start, GFP_KERNEL);
|
||||||
if (!priv->membase) {
|
if (!priv->membase) {
|
||||||
dev_err(&pdev->dev, "cannot allocate DMA buffer\n");
|
dev_err(&pdev->dev, "cannot allocate DMA buffer\n");
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate ring-buffer space at the end of the allocated memory */
|
/* Allocate ring-buffer space at the end of the allocated memory */
|
||||||
|
@ -2581,7 +2564,7 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
dev->irq = platform_get_irq(pdev, 0);
|
dev->irq = platform_get_irq(pdev, 0);
|
||||||
if (dev->irq < 0) {
|
if (dev->irq < 0) {
|
||||||
dev_err(&pdev->dev, "cannot obtain network-device IRQ\n");
|
dev_err(&pdev->dev, "cannot obtain network-device IRQ\n");
|
||||||
goto err_free;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = devm_request_irq(&pdev->dev, dev->irq, priv->r->net_irq,
|
err = devm_request_irq(&pdev->dev, dev->irq, priv->r->net_irq,
|
||||||
|
@ -2589,7 +2572,7 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&pdev->dev, "%s: could not acquire interrupt: %d\n",
|
dev_err(&pdev->dev, "%s: could not acquire interrupt: %d\n",
|
||||||
__func__, err);
|
__func__, err);
|
||||||
goto err_free;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtl8380_init_mac(priv);
|
rtl8380_init_mac(priv);
|
||||||
|
@ -2628,11 +2611,11 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
err = rtl838x_mdio_init(priv);
|
err = rtl838x_mdio_init(priv);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_free;
|
return err;
|
||||||
|
|
||||||
err = register_netdev(dev);
|
err = devm_register_netdev(&pdev->dev, dev);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_free;
|
return err;
|
||||||
|
|
||||||
for (int i = 0; i < priv->rxrings; i++) {
|
for (int i = 0; i < priv->rxrings; i++) {
|
||||||
priv->rx_qs[i].id = i;
|
priv->rx_qs[i].id = i;
|
||||||
|
@ -2646,8 +2629,7 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
err = of_get_phy_mode(dn, &phy_mode);
|
err = of_get_phy_mode(dn, &phy_mode);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&pdev->dev, "incorrect phy-mode\n");
|
dev_err(&pdev->dev, "incorrect phy-mode\n");
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->pcs.ops = &rtl838x_pcs_ops;
|
priv->pcs.ops = &rtl838x_pcs_ops;
|
||||||
|
@ -2658,19 +2640,11 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
|
||||||
phylink = phylink_create(&priv->phylink_config, pdev->dev.fwnode,
|
phylink = phylink_create(&priv->phylink_config, pdev->dev.fwnode,
|
||||||
phy_mode, &rtl838x_phylink_ops);
|
phy_mode, &rtl838x_phylink_ops);
|
||||||
|
|
||||||
if (IS_ERR(phylink)) {
|
if (IS_ERR(phylink))
|
||||||
err = PTR_ERR(phylink);
|
return PTR_ERR(phylink);
|
||||||
goto err_free;
|
|
||||||
}
|
|
||||||
priv->phylink = phylink;
|
priv->phylink = phylink;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_free:
|
|
||||||
pr_err("Error setting up netdev, freeing it again.\n");
|
|
||||||
free_netdev(dev);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtl838x_eth_remove(struct platform_device *pdev)
|
static int rtl838x_eth_remove(struct platform_device *pdev)
|
||||||
|
@ -2680,16 +2654,12 @@ static int rtl838x_eth_remove(struct platform_device *pdev)
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
pr_info("Removing platform driver for rtl838x-eth\n");
|
pr_info("Removing platform driver for rtl838x-eth\n");
|
||||||
rtl838x_mdio_remove(priv);
|
|
||||||
rtl838x_hw_stop(priv);
|
rtl838x_hw_stop(priv);
|
||||||
|
|
||||||
netif_tx_stop_all_queues(dev);
|
netif_tx_stop_all_queues(dev);
|
||||||
|
|
||||||
for (int i = 0; i < priv->rxrings; i++)
|
for (int i = 0; i < priv->rxrings; i++)
|
||||||
netif_napi_del(&priv->rx_qs[i].napi);
|
netif_napi_del(&priv->rx_qs[i].napi);
|
||||||
|
|
||||||
unregister_netdev(dev);
|
|
||||||
free_netdev(dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue