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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 25, 2021 at 06:35:17AM +0000, Joel Stanley wrote:
> > > +
> > > +     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



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux