mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 03:27:44 -04:00
net: add devm version of alloc_etherdev_mqs function
This patch adds devm_alloc_etherdev_mqs function and devm_alloc_etherdev macro. These can be used for simpler netdev allocation without having to care about calling free_netdev. Thanks to this change drivers, their error paths and removal paths may get simpler by a bit. Signed-off-by: Rafał Miłecki <[email protected]> Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
parent
936f459bea
commit
40be0dda07
2 changed files with 33 additions and 0 deletions
|
|
@ -392,6 +392,34 @@ struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
|
|||
}
|
||||
EXPORT_SYMBOL(alloc_etherdev_mqs);
|
||||
|
||||
static void devm_free_netdev(struct device *dev, void *res)
|
||||
{
|
||||
free_netdev(*(struct net_device **)res);
|
||||
}
|
||||
|
||||
struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
|
||||
unsigned int txqs, unsigned int rxqs)
|
||||
{
|
||||
struct net_device **dr;
|
||||
struct net_device *netdev;
|
||||
|
||||
dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
|
||||
if (!dr)
|
||||
return NULL;
|
||||
|
||||
netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
|
||||
if (!netdev) {
|
||||
devres_free(dr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*dr = netdev;
|
||||
devres_add(dev, dr);
|
||||
|
||||
return netdev;
|
||||
}
|
||||
EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
|
||||
|
||||
ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
|
||||
{
|
||||
return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);
|
||||
|
|
|
|||
Loading…
Reference in a new issue