diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-09-23 19:51:51 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-09-26 22:04:08 -0400 |
commit | a7855c78a24d6348e989bec616318e68c662e78b (patch) | |
tree | 43ee591745e17569ad212be6ec3c46e58b443c0a /drivers | |
parent | 83180af0b0ea166adf8249f4513beb7355f9b4c9 (diff) |
net: loopback driver cleanup
loopback driver uses dev->ml_priv to store its percpu stats pointer.
It uses ugly casts "(void __percpu __force *)" to shut up sparse
complains.
Define an union to better document we use ml_priv in loopback driver and
define a lstats field with appropriate types.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/loopback.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 9a0996795321..4b0e30b564e5 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c | |||
@@ -74,7 +74,6 @@ struct pcpu_lstats { | |||
74 | static netdev_tx_t loopback_xmit(struct sk_buff *skb, | 74 | static netdev_tx_t loopback_xmit(struct sk_buff *skb, |
75 | struct net_device *dev) | 75 | struct net_device *dev) |
76 | { | 76 | { |
77 | struct pcpu_lstats __percpu *pcpu_lstats; | ||
78 | struct pcpu_lstats *lb_stats; | 77 | struct pcpu_lstats *lb_stats; |
79 | int len; | 78 | int len; |
80 | 79 | ||
@@ -83,8 +82,7 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb, | |||
83 | skb->protocol = eth_type_trans(skb, dev); | 82 | skb->protocol = eth_type_trans(skb, dev); |
84 | 83 | ||
85 | /* it's OK to use per_cpu_ptr() because BHs are off */ | 84 | /* it's OK to use per_cpu_ptr() because BHs are off */ |
86 | pcpu_lstats = (void __percpu __force *)dev->ml_priv; | 85 | lb_stats = this_cpu_ptr(dev->lstats); |
87 | lb_stats = this_cpu_ptr(pcpu_lstats); | ||
88 | 86 | ||
89 | len = skb->len; | 87 | len = skb->len; |
90 | if (likely(netif_rx(skb) == NET_RX_SUCCESS)) { | 88 | if (likely(netif_rx(skb) == NET_RX_SUCCESS)) { |
@@ -101,19 +99,17 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb, | |||
101 | static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev, | 99 | static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev, |
102 | struct rtnl_link_stats64 *stats) | 100 | struct rtnl_link_stats64 *stats) |
103 | { | 101 | { |
104 | const struct pcpu_lstats __percpu *pcpu_lstats; | ||
105 | u64 bytes = 0; | 102 | u64 bytes = 0; |
106 | u64 packets = 0; | 103 | u64 packets = 0; |
107 | u64 drops = 0; | 104 | u64 drops = 0; |
108 | int i; | 105 | int i; |
109 | 106 | ||
110 | pcpu_lstats = (void __percpu __force *)dev->ml_priv; | ||
111 | for_each_possible_cpu(i) { | 107 | for_each_possible_cpu(i) { |
112 | const struct pcpu_lstats *lb_stats; | 108 | const struct pcpu_lstats *lb_stats; |
113 | u64 tbytes, tpackets; | 109 | u64 tbytes, tpackets; |
114 | unsigned int start; | 110 | unsigned int start; |
115 | 111 | ||
116 | lb_stats = per_cpu_ptr(pcpu_lstats, i); | 112 | lb_stats = per_cpu_ptr(dev->lstats, i); |
117 | do { | 113 | do { |
118 | start = u64_stats_fetch_begin(&lb_stats->syncp); | 114 | start = u64_stats_fetch_begin(&lb_stats->syncp); |
119 | tbytes = lb_stats->bytes; | 115 | tbytes = lb_stats->bytes; |
@@ -147,22 +143,16 @@ static const struct ethtool_ops loopback_ethtool_ops = { | |||
147 | 143 | ||
148 | static int loopback_dev_init(struct net_device *dev) | 144 | static int loopback_dev_init(struct net_device *dev) |
149 | { | 145 | { |
150 | struct pcpu_lstats __percpu *lstats; | 146 | dev->lstats = alloc_percpu(struct pcpu_lstats); |
151 | 147 | if (!dev->lstats) | |
152 | lstats = alloc_percpu(struct pcpu_lstats); | ||
153 | if (!lstats) | ||
154 | return -ENOMEM; | 148 | return -ENOMEM; |
155 | 149 | ||
156 | dev->ml_priv = (void __force *)lstats; | ||
157 | return 0; | 150 | return 0; |
158 | } | 151 | } |
159 | 152 | ||
160 | static void loopback_dev_free(struct net_device *dev) | 153 | static void loopback_dev_free(struct net_device *dev) |
161 | { | 154 | { |
162 | struct pcpu_lstats __percpu *lstats = | 155 | free_percpu(dev->lstats); |
163 | (void __percpu __force *)dev->ml_priv; | ||
164 | |||
165 | free_percpu(lstats); | ||
166 | free_netdev(dev); | 156 | free_netdev(dev); |
167 | } | 157 | } |
168 | 158 | ||