ramips: fix cd-poll sd card remove randomly
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-4.4 / 072-net-add-devm-version-of-alloc_etherdev_mqs-function.patch
1 From 40be0dda0725886b623d67868db3219a2e74683b Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Sat, 28 Jan 2017 15:15:42 +0100
4 Subject: [PATCH] net: add devm version of alloc_etherdev_mqs function
5
6 This patch adds devm_alloc_etherdev_mqs function and devm_alloc_etherdev
7 macro. These can be used for simpler netdev allocation without having to
8 care about calling free_netdev.
9
10 Thanks to this change drivers, their error paths and removal paths may
11 get simpler by a bit.
12
13 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 ---
16 include/linux/etherdevice.h | 5 +++++
17 net/ethernet/eth.c | 28 ++++++++++++++++++++++++++++
18 2 files changed, 33 insertions(+)
19
20 --- a/include/linux/etherdevice.h
21 +++ b/include/linux/etherdevice.h
22 @@ -51,6 +51,11 @@ struct net_device *alloc_etherdev_mqs(in
23 #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
24 #define alloc_etherdev_mq(sizeof_priv, count) alloc_etherdev_mqs(sizeof_priv, count, count)
25
26 +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
27 + unsigned int txqs,
28 + unsigned int rxqs);
29 +#define devm_alloc_etherdev(dev, sizeof_priv) devm_alloc_etherdev_mqs(dev, sizeof_priv, 1, 1)
30 +
31 struct sk_buff **eth_gro_receive(struct sk_buff **head,
32 struct sk_buff *skb);
33 int eth_gro_complete(struct sk_buff *skb, int nhoff);
34 --- a/net/ethernet/eth.c
35 +++ b/net/ethernet/eth.c
36 @@ -388,6 +388,34 @@ struct net_device *alloc_etherdev_mqs(in
37 }
38 EXPORT_SYMBOL(alloc_etherdev_mqs);
39
40 +static void devm_free_netdev(struct device *dev, void *res)
41 +{
42 + free_netdev(*(struct net_device **)res);
43 +}
44 +
45 +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
46 + unsigned int txqs, unsigned int rxqs)
47 +{
48 + struct net_device **dr;
49 + struct net_device *netdev;
50 +
51 + dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
52 + if (!dr)
53 + return NULL;
54 +
55 + netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
56 + if (!netdev) {
57 + devres_free(dr);
58 + return NULL;
59 + }
60 +
61 + *dr = netdev;
62 + devres_add(dev, dr);
63 +
64 + return netdev;
65 +}
66 +EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
67 +
68 ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
69 {
70 return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);