Thread (14 messages) flat view 14 messages, 5 authors, 2021-08-27

Re: [PATCH v2 2/2] net: Add driver for LiteX's LiteEth network interface

From: "Gabriel L. Somlo" <gsomlo@gmail.com>
Date: 2021-08-25 12:00:16
Also in: lkml, netdev

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help