2020-05-23 21:27:08 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
/*
|
|
|
|
* This file contains all networking devres helpers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
|
2020-05-23 21:27:09 +08:00
|
|
|
struct net_device_devres {
|
|
|
|
struct net_device *ndev;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void devm_free_netdev(struct device *dev, void *this)
|
2020-05-23 21:27:08 +08:00
|
|
|
{
|
2020-05-23 21:27:09 +08:00
|
|
|
struct net_device_devres *res = this;
|
|
|
|
|
|
|
|
free_netdev(res->ndev);
|
2020-05-23 21:27:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
|
|
|
|
unsigned int txqs, unsigned int rxqs)
|
|
|
|
{
|
2020-05-23 21:27:09 +08:00
|
|
|
struct net_device_devres *dr;
|
2020-05-23 21:27:08 +08:00
|
|
|
|
|
|
|
dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
|
|
|
|
if (!dr)
|
|
|
|
return NULL;
|
|
|
|
|
2020-05-23 21:27:09 +08:00
|
|
|
dr->ndev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
|
|
|
|
if (!dr->ndev) {
|
2020-05-23 21:27:08 +08:00
|
|
|
devres_free(dr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
devres_add(dev, dr);
|
|
|
|
|
2020-05-23 21:27:09 +08:00
|
|
|
return dr->ndev;
|
2020-05-23 21:27:08 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
|