1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Date: Sat, 28 Jan 2017 15:15:42 +0100
3 Subject: [PATCH] net: add devm version of alloc_etherdev_mqs function
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
8 This patch adds devm_alloc_etherdev_mqs function and devm_alloc_etherdev
9 macro. These can be used for simpler netdev allocation without having to
10 care about calling free_netdev.
12 Thanks to this change drivers, their error paths and removal paths may
15 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
19 --- a/include/linux/etherdevice.h
20 +++ b/include/linux/etherdevice.h
21 @@ -54,6 +54,11 @@ struct net_device *alloc_etherdev_mqs(in
22 #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
23 #define alloc_etherdev_mq(sizeof_priv, count) alloc_etherdev_mqs(sizeof_priv, count, count)
25 +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
28 +#define devm_alloc_etherdev(dev, sizeof_priv) devm_alloc_etherdev_mqs(dev, sizeof_priv, 1, 1)
30 struct sk_buff **eth_gro_receive(struct sk_buff **head,
32 int eth_gro_complete(struct sk_buff *skb, int nhoff);
33 --- a/net/ethernet/eth.c
34 +++ b/net/ethernet/eth.c
35 @@ -391,6 +391,34 @@ struct net_device *alloc_etherdev_mqs(in
37 EXPORT_SYMBOL(alloc_etherdev_mqs);
39 +static void devm_free_netdev(struct device *dev, void *res)
41 + free_netdev(*(struct net_device **)res);
44 +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
45 + unsigned int txqs, unsigned int rxqs)
47 + struct net_device **dr;
48 + struct net_device *netdev;
50 + dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
54 + netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
61 + devres_add(dev, dr);
65 +EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
67 ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
69 return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);