Skip to content

Commit 2239f06

Browse files
committed
Merge: CNB96: net: create a dummy net_device allocator
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5264 JIRA: https://issues.redhat.com/browse/RHEL-59092 Signed-off-by: Izabela Bakollari <ibakolla@redhat.com> Approved-by: Sabrina Dubroca <sdubroca@redhat.com> Approved-by: Ivan Vecera <ivecera@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2 parents f60f357 + 6804d23 commit 2239f06

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

include/linux/netdevice.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3180,7 +3180,7 @@ static inline void unregister_netdevice(struct net_device *dev)
31803180
int netdev_refcnt_read(const struct net_device *dev);
31813181
void free_netdev(struct net_device *dev);
31823182
void netdev_freemem(struct net_device *dev);
3183-
int init_dummy_netdev(struct net_device *dev);
3183+
void init_dummy_netdev(struct net_device *dev);
31843184

31853185
struct net_device *netdev_get_xmit_slave(struct net_device *dev,
31863186
struct sk_buff *skb,
@@ -4583,6 +4583,9 @@ static inline void netif_addr_unlock_bh(struct net_device *dev)
45834583

45844584
void ether_setup(struct net_device *dev);
45854585

4586+
/* Allocate dummy net_device */
4587+
struct net_device *alloc_netdev_dummy(int sizeof_priv);
4588+
45864589
/* Support for loadable net-drivers */
45874590
struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
45884591
unsigned char name_assign_type,

net/core/dev.c

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10158,25 +10158,12 @@ int register_netdevice(struct net_device *dev)
1015810158
}
1015910159
EXPORT_SYMBOL(register_netdevice);
1016010160

10161-
/**
10162-
* init_dummy_netdev - init a dummy network device for NAPI
10163-
* @dev: device to init
10164-
*
10165-
* This takes a network device structure and initialize the minimum
10166-
* amount of fields so it can be used to schedule NAPI polls without
10167-
* registering a full blown interface. This is to be used by drivers
10168-
* that need to tie several hardware interfaces to a single NAPI
10169-
* poll scheduler due to HW limitations.
10161+
/* Initialize the core of a dummy net device.
10162+
* This is useful if you are calling this function after alloc_netdev(),
10163+
* since it does not memset the net_device fields.
1017010164
*/
10171-
int init_dummy_netdev(struct net_device *dev)
10165+
static void init_dummy_netdev_core(struct net_device *dev)
1017210166
{
10173-
/* Clear everything. Note we don't initialize spinlocks
10174-
* are they aren't supposed to be taken by any of the
10175-
* NAPI code and this dummy netdev is supposed to be
10176-
* only ever used for NAPI polls
10177-
*/
10178-
memset(dev, 0, sizeof(struct net_device));
10179-
1018010167
/* make sure we BUG if trying to hit standard
1018110168
* register/unregister code path
1018210169
*/
@@ -10196,12 +10183,30 @@ int init_dummy_netdev(struct net_device *dev)
1019610183
* because users of this 'device' dont need to change
1019710184
* its refcount.
1019810185
*/
10186+
}
1019910187

10200-
return 0;
10188+
/**
10189+
* init_dummy_netdev - init a dummy network device for NAPI
10190+
* @dev: device to init
10191+
*
10192+
* This takes a network device structure and initializes the minimum
10193+
* amount of fields so it can be used to schedule NAPI polls without
10194+
* registering a full blown interface. This is to be used by drivers
10195+
* that need to tie several hardware interfaces to a single NAPI
10196+
* poll scheduler due to HW limitations.
10197+
*/
10198+
void init_dummy_netdev(struct net_device *dev)
10199+
{
10200+
/* Clear everything. Note we don't initialize spinlocks
10201+
* as they aren't supposed to be taken by any of the
10202+
* NAPI code and this dummy netdev is supposed to be
10203+
* only ever used for NAPI polls
10204+
*/
10205+
memset(dev, 0, sizeof(struct net_device));
10206+
init_dummy_netdev_core(dev);
1020110207
}
1020210208
EXPORT_SYMBOL_GPL(init_dummy_netdev);
1020310209

10204-
1020510210
/**
1020610211
* register_netdev - register a network device
1020710212
* @dev: device to register
@@ -10776,7 +10781,8 @@ void free_netdev(struct net_device *dev)
1077610781
dev->xdp_bulkq = NULL;
1077710782

1077810783
/* Compatibility with error handling in drivers */
10779-
if (dev->reg_state == NETREG_UNINITIALIZED) {
10784+
if (dev->reg_state == NETREG_UNINITIALIZED ||
10785+
dev->reg_state == NETREG_DUMMY) {
1078010786
netdev_freemem(dev);
1078110787
return;
1078210788
}
@@ -10789,6 +10795,19 @@ void free_netdev(struct net_device *dev)
1078910795
}
1079010796
EXPORT_SYMBOL(free_netdev);
1079110797

10798+
/**
10799+
* alloc_netdev_dummy - Allocate and initialize a dummy net device.
10800+
* @sizeof_priv: size of private data to allocate space for
10801+
*
10802+
* Return: the allocated net_device on success, NULL otherwise
10803+
*/
10804+
struct net_device *alloc_netdev_dummy(int sizeof_priv)
10805+
{
10806+
return alloc_netdev(sizeof_priv, "dummy#", NET_NAME_UNKNOWN,
10807+
init_dummy_netdev_core);
10808+
}
10809+
EXPORT_SYMBOL_GPL(alloc_netdev_dummy);
10810+
1079210811
/**
1079310812
* synchronize_net - Synchronize with packet receive processing
1079410813
*

0 commit comments

Comments
 (0)