Skip to content

Commit cb8a14b

Browse files
brgldavem330
authored andcommitted
net: move devres helpers into a separate source file
There's currently only a single devres helper in net/ - devm variant of alloc_etherdev. Let's move it to net/devres.c with the intention of assing a second one: devm_register_netdev(). This new routine will need to know the address of the release function of devm_alloc_etherdev() so that it can verify (using devres_find()) that the struct net_device that's being passed to it is also resource managed. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7eef3d0 commit cb8a14b

3 files changed

Lines changed: 37 additions & 29 deletions

File tree

‎net/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Rewritten to use lists instead of if-statements.
77
#
88

9-
obj-$(CONFIG_NET) := socket.o core/
9+
obj-$(CONFIG_NET) := devres.o socket.o core/
1010

1111
tmp-$(CONFIG_COMPAT) := compat.o
1212
obj-$(CONFIG_NET) += $(tmp-y)

‎net/devres.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
10+
static void devm_free_netdev(struct device *dev, void *res)
11+
{
12+
free_netdev(*(struct net_device **)res);
13+
}
14+
15+
struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
16+
unsigned int txqs, unsigned int rxqs)
17+
{
18+
struct net_device **dr;
19+
struct net_device *netdev;
20+
21+
dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
22+
if (!dr)
23+
return NULL;
24+
25+
netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
26+
if (!netdev) {
27+
devres_free(dr);
28+
return NULL;
29+
}
30+
31+
*dr = netdev;
32+
devres_add(dev, dr);
33+
34+
return netdev;
35+
}
36+
EXPORT_SYMBOL(devm_alloc_etherdev_mqs);

‎net/ethernet/eth.c‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -400,34 +400,6 @@ struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
400400
}
401401
EXPORT_SYMBOL(alloc_etherdev_mqs);
402402

403-
static void devm_free_netdev(struct device *dev, void *res)
404-
{
405-
free_netdev(*(struct net_device **)res);
406-
}
407-
408-
struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
409-
unsigned int txqs, unsigned int rxqs)
410-
{
411-
struct net_device **dr;
412-
struct net_device *netdev;
413-
414-
dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
415-
if (!dr)
416-
return NULL;
417-
418-
netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
419-
if (!netdev) {
420-
devres_free(dr);
421-
return NULL;
422-
}
423-
424-
*dr = netdev;
425-
devres_add(dev, dr);
426-
427-
return netdev;
428-
}
429-
EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
430-
431403
ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
432404
{
433405
return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);

0 commit comments

Comments
 (0)