Commit | Line | Data |
---|---|---|
cb8a14b2 BG |
1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | /* | |
3 | * This file contains all networking devres helpers. | |
4 | */ | |
5 | ||
6 | #include <linux/device.h> | |
7 | #include <linux/etherdevice.h> | |
8 | #include <linux/netdevice.h> | |
9 | ||
f75063ab BG |
10 | struct net_device_devres { |
11 | struct net_device *ndev; | |
12 | }; | |
13 | ||
14 | static void devm_free_netdev(struct device *dev, void *this) | |
cb8a14b2 | 15 | { |
f75063ab BG |
16 | struct net_device_devres *res = this; |
17 | ||
18 | free_netdev(res->ndev); | |
cb8a14b2 BG |
19 | } |
20 | ||
21 | struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv, | |
22 | unsigned int txqs, unsigned int rxqs) | |
23 | { | |
f75063ab | 24 | struct net_device_devres *dr; |
cb8a14b2 BG |
25 | |
26 | dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL); | |
27 | if (!dr) | |
28 | return NULL; | |
29 | ||
f75063ab BG |
30 | dr->ndev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs); |
31 | if (!dr->ndev) { | |
cb8a14b2 BG |
32 | devres_free(dr); |
33 | return NULL; | |
34 | } | |
35 | ||
cb8a14b2 BG |
36 | devres_add(dev, dr); |
37 | ||
f75063ab | 38 | return dr->ndev; |
cb8a14b2 BG |
39 | } |
40 | EXPORT_SYMBOL(devm_alloc_etherdev_mqs); |