On Wed, Aug 25, 2021 at 06:35:17AM +0000, Joel Stanley wrote:
quoted
quoted
+
+ netdev = devm_alloc_etherdev(&pdev->dev, sizeof(*priv));
+ if (!netdev)
+ return -ENOMEM;
+
+ SET_NETDEV_DEV(netdev, &pdev->dev);
+ platform_set_drvdata(pdev, netdev);
+
+ priv = netdev_priv(netdev);
+ priv->netdev = netdev;
+ priv->dev = &pdev->dev;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0) {
+ dev_err(&pdev->dev, "Failed to get IRQ %d\n", irq);
+ return irq;
At this point, netdev has been dynamically allocated, and should
probably be free'd before liteeth_probe() is allowed to fail,
to avoid any potential leaks...
We use the managed variant of alloc_etherdev, which means the
structure is freed by the driver core when the driver is removed. This
saves having to open code the cleanup/free code.
Have a read of Documentation/driver-api/driver-model/devres.rst for
more information.
That makes sense, thanks for the link!
Cheers,
--Gabriel