kernel: bump 4.9 to 4.9.146
[openwrt/openwrt.git] / target / linux / generic / backport-4.9 / 022-net-add-devm-version-of-alloc_etherdev_mqs-function.patch
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
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
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.
11
12 Thanks to this change drivers, their error paths and removal paths may
13 get simpler by a bit.
14
15 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
17 ---
18
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)
24
25 +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
26 + unsigned int txqs,
27 + unsigned int rxqs);
28 +#define devm_alloc_etherdev(dev, sizeof_priv) devm_alloc_etherdev_mqs(dev, sizeof_priv, 1, 1)
29 +
30 struct sk_buff **eth_gro_receive(struct sk_buff **head,
31 struct sk_buff *skb);
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
36 }
37 EXPORT_SYMBOL(alloc_etherdev_mqs);
38
39 +static void devm_free_netdev(struct device *dev, void *res)
40 +{
41 + free_netdev(*(struct net_device **)res);
42 +}
43 +
44 +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
45 + unsigned int txqs, unsigned int rxqs)
46 +{
47 + struct net_device **dr;
48 + struct net_device *netdev;
49 +
50 + dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
51 + if (!dr)
52 + return NULL;
53 +
54 + netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
55 + if (!netdev) {
56 + devres_free(dr);
57 + return NULL;
58 + }
59 +
60 + *dr = netdev;
61 + devres_add(dev, dr);
62 +
63 + return netdev;
64 +}
65 +EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
66 +
67 ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
68 {
69 return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);