aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/802/p8023.c3
-rw-r--r--net/ax25/af_ax25.c6
-rw-r--r--net/ax25/ax25_in.c6
-rw-r--r--net/ax25/ax25_route.c19
-rw-r--r--net/bluetooth/af_bluetooth.c12
-rw-r--r--net/bluetooth/hci_core.c2
-rw-r--r--net/bluetooth/hci_event.c6
-rw-r--r--net/bluetooth/hci_sock.c2
-rw-r--r--net/bluetooth/hci_sysfs.c4
-rw-r--r--net/bluetooth/hidp/core.c4
-rw-r--r--net/bluetooth/l2cap.c98
-rw-r--r--net/bluetooth/rfcomm/core.c124
-rw-r--r--net/bluetooth/rfcomm/sock.c90
-rw-r--r--net/bluetooth/sco.c92
-rw-r--r--net/core/dev_mcast.c3
-rw-r--r--net/core/sock.c3
-rw-r--r--net/dccp/ipv4.c6
-rw-r--r--net/dccp/proto.c3
-rw-r--r--net/decnet/dn_table.c14
-rw-r--r--net/ethernet/pe2.c3
-rw-r--r--net/ipv4/af_inet.c3
-rw-r--r--net/ipv4/fib_frontend.c3
-rw-r--r--net/ipv4/ip_options.c3
-rw-r--r--net/ipv4/ip_output.c15
-rw-r--r--net/ipv4/ip_sockglue.c12
-rw-r--r--net/ipv4/ipvs/ip_vs_app.c6
-rw-r--r--net/ipv4/ipvs/ip_vs_core.c7
-rw-r--r--net/ipv4/multipath_wrandom.c10
-rw-r--r--net/ipv4/netfilter/ip_nat_snmp_basic.c3
-rw-r--r--net/ipv4/tcp_ipv4.c3
-rw-r--r--net/ipv6/addrconf.c433
-rw-r--r--net/ipv6/ip6_fib.c54
-rw-r--r--net/ipv6/ip6_output.c15
-rw-r--r--net/ipv6/ip6_tunnel.c6
-rw-r--r--net/ipv6/ipcomp6.c3
-rw-r--r--net/ipv6/ipv6_sockglue.c3
-rw-r--r--net/ipv6/ipv6_syms.c2
-rw-r--r--net/irda/discovery.c3
-rw-r--r--net/irda/irias_object.c16
-rw-r--r--net/rose/rose_route.c6
-rw-r--r--net/sched/cls_fw.c3
-rw-r--r--net/sched/cls_route.c3
-rw-r--r--net/sched/cls_rsvp.h3
-rw-r--r--net/sched/cls_tcindex.c9
-rw-r--r--net/sched/cls_u32.c4
-rw-r--r--net/sched/em_meta.c3
-rw-r--r--net/sched/ematch.c5
-rw-r--r--net/sctp/associola.c4
-rw-r--r--net/sctp/sm_make_chunk.c6
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_seal.c2
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_unseal.c2
-rw-r--r--net/sunrpc/auth_gss/gss_mech_switch.c3
-rw-r--r--net/sunrpc/auth_gss/gss_spkm3_seal.c3
-rw-r--r--net/sunrpc/auth_gss/gss_spkm3_token.c3
-rw-r--r--net/sunrpc/auth_gss/gss_spkm3_unseal.c6
-rw-r--r--net/sunrpc/rpc_pipe.c6
-rw-r--r--net/sunrpc/svc.c9
-rw-r--r--net/sunrpc/xdr.c3
-rw-r--r--net/unix/af_unix.c2
-rw-r--r--net/wanrouter/af_wanpipe.c20
-rw-r--r--net/wanrouter/wanmain.c12
-rw-r--r--net/xfrm/xfrm_state.c12
62 files changed, 469 insertions, 760 deletions
diff --git a/net/802/p8023.c b/net/802/p8023.c
index 6368d3dce444..d23e906456eb 100644
--- a/net/802/p8023.c
+++ b/net/802/p8023.c
@@ -54,8 +54,7 @@ struct datalink_proto *make_8023_client(void)
54 */ 54 */
55void destroy_8023_client(struct datalink_proto *dl) 55void destroy_8023_client(struct datalink_proto *dl)
56{ 56{
57 if (dl) 57 kfree(dl);
58 kfree(dl);
59} 58}
60 59
61EXPORT_SYMBOL(destroy_8023_client); 60EXPORT_SYMBOL(destroy_8023_client);
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index 8e37e71e34ff..1b683f302657 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1138,10 +1138,8 @@ static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
1138 sk->sk_state = TCP_CLOSE; 1138 sk->sk_state = TCP_CLOSE;
1139 sock->state = SS_UNCONNECTED; 1139 sock->state = SS_UNCONNECTED;
1140 1140
1141 if (ax25->digipeat != NULL) { 1141 kfree(ax25->digipeat);
1142 kfree(ax25->digipeat); 1142 ax25->digipeat = NULL;
1143 ax25->digipeat = NULL;
1144 }
1145 1143
1146 /* 1144 /*
1147 * Handle digi-peaters to be used. 1145 * Handle digi-peaters to be used.
diff --git a/net/ax25/ax25_in.c b/net/ax25/ax25_in.c
index 73cfc3411c46..4cf87540fb3a 100644
--- a/net/ax25/ax25_in.c
+++ b/net/ax25/ax25_in.c
@@ -401,10 +401,8 @@ static int ax25_rcv(struct sk_buff *skb, struct net_device *dev,
401 } 401 }
402 402
403 if (dp.ndigi == 0) { 403 if (dp.ndigi == 0) {
404 if (ax25->digipeat != NULL) { 404 kfree(ax25->digipeat);
405 kfree(ax25->digipeat); 405 ax25->digipeat = NULL;
406 ax25->digipeat = NULL;
407 }
408 } else { 406 } else {
409 /* Reverse the source SABM's path */ 407 /* Reverse the source SABM's path */
410 memcpy(ax25->digipeat, &reverse_dp, sizeof(ax25_digi)); 408 memcpy(ax25->digipeat, &reverse_dp, sizeof(ax25_digi));
diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c
index 26b77d972220..b1e945bd6ed3 100644
--- a/net/ax25/ax25_route.c
+++ b/net/ax25/ax25_route.c
@@ -54,15 +54,13 @@ void ax25_rt_device_down(struct net_device *dev)
54 if (s->dev == dev) { 54 if (s->dev == dev) {
55 if (ax25_route_list == s) { 55 if (ax25_route_list == s) {
56 ax25_route_list = s->next; 56 ax25_route_list = s->next;
57 if (s->digipeat != NULL) 57 kfree(s->digipeat);
58 kfree(s->digipeat);
59 kfree(s); 58 kfree(s);
60 } else { 59 } else {
61 for (t = ax25_route_list; t != NULL; t = t->next) { 60 for (t = ax25_route_list; t != NULL; t = t->next) {
62 if (t->next == s) { 61 if (t->next == s) {
63 t->next = s->next; 62 t->next = s->next;
64 if (s->digipeat != NULL) 63 kfree(s->digipeat);
65 kfree(s->digipeat);
66 kfree(s); 64 kfree(s);
67 break; 65 break;
68 } 66 }
@@ -90,10 +88,8 @@ static int ax25_rt_add(struct ax25_routes_struct *route)
90 while (ax25_rt != NULL) { 88 while (ax25_rt != NULL) {
91 if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 && 89 if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 &&
92 ax25_rt->dev == ax25_dev->dev) { 90 ax25_rt->dev == ax25_dev->dev) {
93 if (ax25_rt->digipeat != NULL) { 91 kfree(ax25_rt->digipeat);
94 kfree(ax25_rt->digipeat); 92 ax25_rt->digipeat = NULL;
95 ax25_rt->digipeat = NULL;
96 }
97 if (route->digi_count != 0) { 93 if (route->digi_count != 0) {
98 if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) { 94 if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
99 write_unlock(&ax25_route_lock); 95 write_unlock(&ax25_route_lock);
@@ -145,8 +141,7 @@ static int ax25_rt_add(struct ax25_routes_struct *route)
145static void ax25_rt_destroy(ax25_route *ax25_rt) 141static void ax25_rt_destroy(ax25_route *ax25_rt)
146{ 142{
147 if (atomic_read(&ax25_rt->ref) == 0) { 143 if (atomic_read(&ax25_rt->ref) == 0) {
148 if (ax25_rt->digipeat != NULL) 144 kfree(ax25_rt->digipeat);
149 kfree(ax25_rt->digipeat);
150 kfree(ax25_rt); 145 kfree(ax25_rt);
151 return; 146 return;
152 } 147 }
@@ -530,9 +525,7 @@ void __exit ax25_rt_free(void)
530 s = ax25_rt; 525 s = ax25_rt;
531 ax25_rt = ax25_rt->next; 526 ax25_rt = ax25_rt->next;
532 527
533 if (s->digipeat != NULL) 528 kfree(s->digipeat);
534 kfree(s->digipeat);
535
536 kfree(s); 529 kfree(s);
537 } 530 }
538 write_unlock(&ax25_route_lock); 531 write_unlock(&ax25_route_lock);
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 03532062a46a..ea616e3fc98e 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -36,7 +36,6 @@
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/poll.h> 38#include <linux/poll.h>
39#include <linux/proc_fs.h>
40#include <net/sock.h> 39#include <net/sock.h>
41 40
42#if defined(CONFIG_KMOD) 41#if defined(CONFIG_KMOD)
@@ -50,10 +49,7 @@
50#define BT_DBG(D...) 49#define BT_DBG(D...)
51#endif 50#endif
52 51
53#define VERSION "2.7" 52#define VERSION "2.8"
54
55struct proc_dir_entry *proc_bt;
56EXPORT_SYMBOL(proc_bt);
57 53
58/* Bluetooth sockets */ 54/* Bluetooth sockets */
59#define BT_MAX_PROTO 8 55#define BT_MAX_PROTO 8
@@ -312,10 +308,6 @@ static int __init bt_init(void)
312{ 308{
313 BT_INFO("Core ver %s", VERSION); 309 BT_INFO("Core ver %s", VERSION);
314 310
315 proc_bt = proc_mkdir("bluetooth", NULL);
316 if (proc_bt)
317 proc_bt->owner = THIS_MODULE;
318
319 sock_register(&bt_sock_family_ops); 311 sock_register(&bt_sock_family_ops);
320 312
321 BT_INFO("HCI device and connection manager initialized"); 313 BT_INFO("HCI device and connection manager initialized");
@@ -334,8 +326,6 @@ static void __exit bt_exit(void)
334 bt_sysfs_cleanup(); 326 bt_sysfs_cleanup();
335 327
336 sock_unregister(PF_BLUETOOTH); 328 sock_unregister(PF_BLUETOOTH);
337
338 remove_proc_entry("bluetooth", NULL);
339} 329}
340 330
341subsys_initcall(bt_init); 331subsys_initcall(bt_init);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index cf0df1c8c933..9106354c781e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -183,7 +183,7 @@ static void hci_reset_req(struct hci_dev *hdev, unsigned long opt)
183static void hci_init_req(struct hci_dev *hdev, unsigned long opt) 183static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
184{ 184{
185 struct sk_buff *skb; 185 struct sk_buff *skb;
186 __u16 param; 186 __le16 param;
187 187
188 BT_DBG("%s %ld", hdev->name, opt); 188 BT_DBG("%s %ld", hdev->name, opt);
189 189
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b61b4e8e36fd..eb64555d1fb3 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -242,7 +242,7 @@ static void hci_cc_host_ctl(struct hci_dev *hdev, __u16 ocf, struct sk_buff *skb
242 break; 242 break;
243 243
244 status = *((__u8 *) skb->data); 244 status = *((__u8 *) skb->data);
245 setting = __le16_to_cpu(get_unaligned((__u16 *) sent)); 245 setting = __le16_to_cpu(get_unaligned((__le16 *) sent));
246 246
247 if (!status && hdev->voice_setting != setting) { 247 if (!status && hdev->voice_setting != setting) {
248 hdev->voice_setting = setting; 248 hdev->voice_setting = setting;
@@ -728,7 +728,7 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff
728static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb) 728static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
729{ 729{
730 struct hci_ev_num_comp_pkts *ev = (struct hci_ev_num_comp_pkts *) skb->data; 730 struct hci_ev_num_comp_pkts *ev = (struct hci_ev_num_comp_pkts *) skb->data;
731 __u16 *ptr; 731 __le16 *ptr;
732 int i; 732 int i;
733 733
734 skb_pull(skb, sizeof(*ev)); 734 skb_pull(skb, sizeof(*ev));
@@ -742,7 +742,7 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
742 742
743 tasklet_disable(&hdev->tx_task); 743 tasklet_disable(&hdev->tx_task);
744 744
745 for (i = 0, ptr = (__u16 *) skb->data; i < ev->num_hndl; i++) { 745 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
746 struct hci_conn *conn; 746 struct hci_conn *conn;
747 __u16 handle, count; 747 __u16 handle, count;
748 748
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 799e448750ad..1d6d0a15c099 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -416,7 +416,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
416 skb->dev = (void *) hdev; 416 skb->dev = (void *) hdev;
417 417
418 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { 418 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) {
419 u16 opcode = __le16_to_cpu(get_unaligned((u16 *)skb->data)); 419 u16 opcode = __le16_to_cpu(get_unaligned((__le16 *) skb->data));
420 u16 ogf = hci_opcode_ogf(opcode); 420 u16 ogf = hci_opcode_ogf(opcode);
421 u16 ocf = hci_opcode_ocf(opcode); 421 u16 ocf = hci_opcode_ocf(opcode);
422 422
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 7856bc26accb..bd7568ac87fc 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -103,7 +103,7 @@ static void bt_release(struct class_device *cdev)
103 kfree(hdev); 103 kfree(hdev);
104} 104}
105 105
106static struct class bt_class = { 106struct class bt_class = {
107 .name = "bluetooth", 107 .name = "bluetooth",
108 .release = bt_release, 108 .release = bt_release,
109#ifdef CONFIG_HOTPLUG 109#ifdef CONFIG_HOTPLUG
@@ -111,6 +111,8 @@ static struct class bt_class = {
111#endif 111#endif
112}; 112};
113 113
114EXPORT_SYMBOL_GPL(bt_class);
115
114int hci_register_sysfs(struct hci_dev *hdev) 116int hci_register_sysfs(struct hci_dev *hdev)
115{ 117{
116 struct class_device *cdev = &hdev->class_dev; 118 struct class_device *cdev = &hdev->class_dev;
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 860444a7fc0f..cdb9cfafd960 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -660,9 +660,7 @@ unlink:
660failed: 660failed:
661 up_write(&hidp_session_sem); 661 up_write(&hidp_session_sem);
662 662
663 if (session->input) 663 kfree(session->input);
664 kfree(session->input);
665
666 kfree(session); 664 kfree(session);
667 return err; 665 return err;
668} 666}
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 59b2dd36baa7..e3bb11ca4235 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -38,9 +38,8 @@
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/socket.h> 39#include <linux/socket.h>
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/proc_fs.h>
42#include <linux/seq_file.h>
43#include <linux/list.h> 41#include <linux/list.h>
42#include <linux/device.h>
44#include <net/sock.h> 43#include <net/sock.h>
45 44
46#include <asm/system.h> 45#include <asm/system.h>
@@ -56,7 +55,7 @@
56#define BT_DBG(D...) 55#define BT_DBG(D...)
57#endif 56#endif
58 57
59#define VERSION "2.7" 58#define VERSION "2.8"
60 59
61static struct proto_ops l2cap_sock_ops; 60static struct proto_ops l2cap_sock_ops;
62 61
@@ -2137,94 +2136,29 @@ drop:
2137 return 0; 2136 return 0;
2138} 2137}
2139 2138
2140/* ---- Proc fs support ---- */ 2139static ssize_t l2cap_sysfs_show(struct class *dev, char *buf)
2141#ifdef CONFIG_PROC_FS
2142static void *l2cap_seq_start(struct seq_file *seq, loff_t *pos)
2143{ 2140{
2144 struct sock *sk; 2141 struct sock *sk;
2145 struct hlist_node *node; 2142 struct hlist_node *node;
2146 loff_t l = *pos; 2143 char *str = buf;
2147 2144
2148 read_lock_bh(&l2cap_sk_list.lock); 2145 read_lock_bh(&l2cap_sk_list.lock);
2149 2146
2150 sk_for_each(sk, node, &l2cap_sk_list.head) 2147 sk_for_each(sk, node, &l2cap_sk_list.head) {
2151 if (!l--) 2148 struct l2cap_pinfo *pi = l2cap_pi(sk);
2152 goto found;
2153 sk = NULL;
2154found:
2155 return sk;
2156}
2157 2149
2158static void *l2cap_seq_next(struct seq_file *seq, void *e, loff_t *pos) 2150 str += sprintf(str, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d 0x%x\n",
2159{ 2151 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
2160 (*pos)++; 2152 sk->sk_state, pi->psm, pi->scid, pi->dcid, pi->imtu,
2161 return sk_next(e); 2153 pi->omtu, pi->link_mode);
2162} 2154 }
2163 2155
2164static void l2cap_seq_stop(struct seq_file *seq, void *e)
2165{
2166 read_unlock_bh(&l2cap_sk_list.lock); 2156 read_unlock_bh(&l2cap_sk_list.lock);
2167}
2168 2157
2169static int l2cap_seq_show(struct seq_file *seq, void *e) 2158 return (str - buf);
2170{
2171 struct sock *sk = e;
2172 struct l2cap_pinfo *pi = l2cap_pi(sk);
2173
2174 seq_printf(seq, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d 0x%x\n",
2175 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
2176 sk->sk_state, pi->psm, pi->scid, pi->dcid, pi->imtu,
2177 pi->omtu, pi->link_mode);
2178 return 0;
2179} 2159}
2180 2160
2181static struct seq_operations l2cap_seq_ops = { 2161static CLASS_ATTR(l2cap, S_IRUGO, l2cap_sysfs_show, NULL);
2182 .start = l2cap_seq_start,
2183 .next = l2cap_seq_next,
2184 .stop = l2cap_seq_stop,
2185 .show = l2cap_seq_show
2186};
2187
2188static int l2cap_seq_open(struct inode *inode, struct file *file)
2189{
2190 return seq_open(file, &l2cap_seq_ops);
2191}
2192
2193static struct file_operations l2cap_seq_fops = {
2194 .owner = THIS_MODULE,
2195 .open = l2cap_seq_open,
2196 .read = seq_read,
2197 .llseek = seq_lseek,
2198 .release = seq_release,
2199};
2200
2201static int __init l2cap_proc_init(void)
2202{
2203 struct proc_dir_entry *p = create_proc_entry("l2cap", S_IRUGO, proc_bt);
2204 if (!p)
2205 return -ENOMEM;
2206 p->owner = THIS_MODULE;
2207 p->proc_fops = &l2cap_seq_fops;
2208 return 0;
2209}
2210
2211static void __exit l2cap_proc_cleanup(void)
2212{
2213 remove_proc_entry("l2cap", proc_bt);
2214}
2215
2216#else /* CONFIG_PROC_FS */
2217
2218static int __init l2cap_proc_init(void)
2219{
2220 return 0;
2221}
2222
2223static void __exit l2cap_proc_cleanup(void)
2224{
2225 return;
2226}
2227#endif /* CONFIG_PROC_FS */
2228 2162
2229static struct proto_ops l2cap_sock_ops = { 2163static struct proto_ops l2cap_sock_ops = {
2230 .family = PF_BLUETOOTH, 2164 .family = PF_BLUETOOTH,
@@ -2266,7 +2200,7 @@ static struct hci_proto l2cap_hci_proto = {
2266static int __init l2cap_init(void) 2200static int __init l2cap_init(void)
2267{ 2201{
2268 int err; 2202 int err;
2269 2203
2270 err = proto_register(&l2cap_proto, 0); 2204 err = proto_register(&l2cap_proto, 0);
2271 if (err < 0) 2205 if (err < 0)
2272 return err; 2206 return err;
@@ -2284,7 +2218,7 @@ static int __init l2cap_init(void)
2284 goto error; 2218 goto error;
2285 } 2219 }
2286 2220
2287 l2cap_proc_init(); 2221 class_create_file(&bt_class, &class_attr_l2cap);
2288 2222
2289 BT_INFO("L2CAP ver %s", VERSION); 2223 BT_INFO("L2CAP ver %s", VERSION);
2290 BT_INFO("L2CAP socket layer initialized"); 2224 BT_INFO("L2CAP socket layer initialized");
@@ -2298,7 +2232,7 @@ error:
2298 2232
2299static void __exit l2cap_exit(void) 2233static void __exit l2cap_exit(void)
2300{ 2234{
2301 l2cap_proc_cleanup(); 2235 class_remove_file(&bt_class, &class_attr_l2cap);
2302 2236
2303 if (bt_sock_unregister(BTPROTO_L2CAP) < 0) 2237 if (bt_sock_unregister(BTPROTO_L2CAP) < 0)
2304 BT_ERR("L2CAP socket unregistration failed"); 2238 BT_ERR("L2CAP socket unregistration failed");
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index c3d56ead840c..0d89d6434136 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -35,9 +35,8 @@
35#include <linux/signal.h> 35#include <linux/signal.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/wait.h> 37#include <linux/wait.h>
38#include <linux/device.h>
38#include <linux/net.h> 39#include <linux/net.h>
39#include <linux/proc_fs.h>
40#include <linux/seq_file.h>
41#include <net/sock.h> 40#include <net/sock.h>
42#include <asm/uaccess.h> 41#include <asm/uaccess.h>
43#include <asm/unaligned.h> 42#include <asm/unaligned.h>
@@ -47,17 +46,13 @@
47#include <net/bluetooth/l2cap.h> 46#include <net/bluetooth/l2cap.h>
48#include <net/bluetooth/rfcomm.h> 47#include <net/bluetooth/rfcomm.h>
49 48
50#define VERSION "1.5" 49#define VERSION "1.6"
51 50
52#ifndef CONFIG_BT_RFCOMM_DEBUG 51#ifndef CONFIG_BT_RFCOMM_DEBUG
53#undef BT_DBG 52#undef BT_DBG
54#define BT_DBG(D...) 53#define BT_DBG(D...)
55#endif 54#endif
56 55
57#ifdef CONFIG_PROC_FS
58struct proc_dir_entry *proc_bt_rfcomm;
59#endif
60
61static struct task_struct *rfcomm_thread; 56static struct task_struct *rfcomm_thread;
62 57
63static DECLARE_MUTEX(rfcomm_sem); 58static DECLARE_MUTEX(rfcomm_sem);
@@ -2001,117 +1996,32 @@ static struct hci_cb rfcomm_cb = {
2001 .encrypt_cfm = rfcomm_encrypt_cfm 1996 .encrypt_cfm = rfcomm_encrypt_cfm
2002}; 1997};
2003 1998
2004/* ---- Proc fs support ---- */ 1999static ssize_t rfcomm_dlc_sysfs_show(struct class *dev, char *buf)
2005#ifdef CONFIG_PROC_FS
2006static void *rfcomm_seq_start(struct seq_file *seq, loff_t *pos)
2007{ 2000{
2008 struct rfcomm_session *s; 2001 struct rfcomm_session *s;
2009 struct list_head *pp, *p; 2002 struct list_head *pp, *p;
2010 loff_t l = *pos; 2003 char *str = buf;
2011 2004
2012 rfcomm_lock(); 2005 rfcomm_lock();
2013 2006
2014 list_for_each(p, &session_list) { 2007 list_for_each(p, &session_list) {
2015 s = list_entry(p, struct rfcomm_session, list); 2008 s = list_entry(p, struct rfcomm_session, list);
2016 list_for_each(pp, &s->dlcs) 2009 list_for_each(pp, &s->dlcs) {
2017 if (!l--) { 2010 struct sock *sk = s->sock->sk;
2018 seq->private = s; 2011 struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list);
2019 return pp;
2020 }
2021 }
2022 return NULL;
2023}
2024 2012
2025static void *rfcomm_seq_next(struct seq_file *seq, void *e, loff_t *pos) 2013 str += sprintf(str, "%s %s %ld %d %d %d %d\n",
2026{ 2014 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
2027 struct rfcomm_session *s = seq->private; 2015 d->state, d->dlci, d->mtu, d->rx_credits, d->tx_credits);
2028 struct list_head *pp, *p = e;
2029 (*pos)++;
2030
2031 if (p->next != &s->dlcs)
2032 return p->next;
2033
2034 list_for_each(p, &session_list) {
2035 s = list_entry(p, struct rfcomm_session, list);
2036 __list_for_each(pp, &s->dlcs) {
2037 seq->private = s;
2038 return pp;
2039 } 2016 }
2040 } 2017 }
2041 return NULL;
2042}
2043 2018
2044static void rfcomm_seq_stop(struct seq_file *seq, void *e)
2045{
2046 rfcomm_unlock(); 2019 rfcomm_unlock();
2047}
2048
2049static int rfcomm_seq_show(struct seq_file *seq, void *e)
2050{
2051 struct rfcomm_session *s = seq->private;
2052 struct sock *sk = s->sock->sk;
2053 struct rfcomm_dlc *d = list_entry(e, struct rfcomm_dlc, list);
2054
2055 seq_printf(seq, "%s %s %ld %d %d %d %d\n",
2056 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
2057 d->state, d->dlci, d->mtu, d->rx_credits, d->tx_credits);
2058 return 0;
2059}
2060
2061static struct seq_operations rfcomm_seq_ops = {
2062 .start = rfcomm_seq_start,
2063 .next = rfcomm_seq_next,
2064 .stop = rfcomm_seq_stop,
2065 .show = rfcomm_seq_show
2066};
2067
2068static int rfcomm_seq_open(struct inode *inode, struct file *file)
2069{
2070 return seq_open(file, &rfcomm_seq_ops);
2071}
2072
2073static struct file_operations rfcomm_seq_fops = {
2074 .owner = THIS_MODULE,
2075 .open = rfcomm_seq_open,
2076 .read = seq_read,
2077 .llseek = seq_lseek,
2078 .release = seq_release,
2079};
2080
2081static int __init rfcomm_proc_init(void)
2082{
2083 struct proc_dir_entry *p;
2084
2085 proc_bt_rfcomm = proc_mkdir("rfcomm", proc_bt);
2086 if (proc_bt_rfcomm) {
2087 proc_bt_rfcomm->owner = THIS_MODULE;
2088
2089 p = create_proc_entry("dlc", S_IRUGO, proc_bt_rfcomm);
2090 if (p)
2091 p->proc_fops = &rfcomm_seq_fops;
2092 }
2093 return 0;
2094}
2095
2096static void __exit rfcomm_proc_cleanup(void)
2097{
2098 remove_proc_entry("dlc", proc_bt_rfcomm);
2099 2020
2100 remove_proc_entry("rfcomm", proc_bt); 2021 return (str - buf);
2101} 2022}
2102 2023
2103#else /* CONFIG_PROC_FS */ 2024static CLASS_ATTR(rfcomm_dlc, S_IRUGO, rfcomm_dlc_sysfs_show, NULL);
2104
2105static int __init rfcomm_proc_init(void)
2106{
2107 return 0;
2108}
2109
2110static void __exit rfcomm_proc_cleanup(void)
2111{
2112 return;
2113}
2114#endif /* CONFIG_PROC_FS */
2115 2025
2116/* ---- Initialization ---- */ 2026/* ---- Initialization ---- */
2117static int __init rfcomm_init(void) 2027static int __init rfcomm_init(void)
@@ -2122,9 +2032,7 @@ static int __init rfcomm_init(void)
2122 2032
2123 kernel_thread(rfcomm_run, NULL, CLONE_KERNEL); 2033 kernel_thread(rfcomm_run, NULL, CLONE_KERNEL);
2124 2034
2125 BT_INFO("RFCOMM ver %s", VERSION); 2035 class_create_file(&bt_class, &class_attr_rfcomm_dlc);
2126
2127 rfcomm_proc_init();
2128 2036
2129 rfcomm_init_sockets(); 2037 rfcomm_init_sockets();
2130 2038
@@ -2132,11 +2040,15 @@ static int __init rfcomm_init(void)
2132 rfcomm_init_ttys(); 2040 rfcomm_init_ttys();
2133#endif 2041#endif
2134 2042
2043 BT_INFO("RFCOMM ver %s", VERSION);
2044
2135 return 0; 2045 return 0;
2136} 2046}
2137 2047
2138static void __exit rfcomm_exit(void) 2048static void __exit rfcomm_exit(void)
2139{ 2049{
2050 class_remove_file(&bt_class, &class_attr_rfcomm_dlc);
2051
2140 hci_unregister_cb(&rfcomm_cb); 2052 hci_unregister_cb(&rfcomm_cb);
2141 2053
2142 /* Terminate working thread. 2054 /* Terminate working thread.
@@ -2153,8 +2065,6 @@ static void __exit rfcomm_exit(void)
2153#endif 2065#endif
2154 2066
2155 rfcomm_cleanup_sockets(); 2067 rfcomm_cleanup_sockets();
2156
2157 rfcomm_proc_cleanup();
2158} 2068}
2159 2069
2160module_init(rfcomm_init); 2070module_init(rfcomm_init);
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index a2b30f0aedb7..6c34261b232e 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -42,8 +42,7 @@
42#include <linux/socket.h> 42#include <linux/socket.h>
43#include <linux/skbuff.h> 43#include <linux/skbuff.h>
44#include <linux/list.h> 44#include <linux/list.h>
45#include <linux/proc_fs.h> 45#include <linux/device.h>
46#include <linux/seq_file.h>
47#include <net/sock.h> 46#include <net/sock.h>
48 47
49#include <asm/system.h> 48#include <asm/system.h>
@@ -887,89 +886,26 @@ done:
887 return result; 886 return result;
888} 887}
889 888
890/* ---- Proc fs support ---- */ 889static ssize_t rfcomm_sock_sysfs_show(struct class *dev, char *buf)
891#ifdef CONFIG_PROC_FS
892static void *rfcomm_seq_start(struct seq_file *seq, loff_t *pos)
893{ 890{
894 struct sock *sk; 891 struct sock *sk;
895 struct hlist_node *node; 892 struct hlist_node *node;
896 loff_t l = *pos; 893 char *str = buf;
897 894
898 read_lock_bh(&rfcomm_sk_list.lock); 895 read_lock_bh(&rfcomm_sk_list.lock);
899 896
900 sk_for_each(sk, node, &rfcomm_sk_list.head) 897 sk_for_each(sk, node, &rfcomm_sk_list.head) {
901 if (!l--) 898 str += sprintf(str, "%s %s %d %d\n",
902 return sk; 899 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
903 return NULL; 900 sk->sk_state, rfcomm_pi(sk)->channel);
904} 901 }
905
906static void *rfcomm_seq_next(struct seq_file *seq, void *e, loff_t *pos)
907{
908 struct sock *sk = e;
909 (*pos)++;
910 return sk_next(sk);
911}
912 902
913static void rfcomm_seq_stop(struct seq_file *seq, void *e)
914{
915 read_unlock_bh(&rfcomm_sk_list.lock); 903 read_unlock_bh(&rfcomm_sk_list.lock);
916}
917 904
918static int rfcomm_seq_show(struct seq_file *seq, void *e) 905 return (str - buf);
919{
920 struct sock *sk = e;
921 seq_printf(seq, "%s %s %d %d\n",
922 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
923 sk->sk_state, rfcomm_pi(sk)->channel);
924 return 0;
925}
926
927static struct seq_operations rfcomm_seq_ops = {
928 .start = rfcomm_seq_start,
929 .next = rfcomm_seq_next,
930 .stop = rfcomm_seq_stop,
931 .show = rfcomm_seq_show
932};
933
934static int rfcomm_seq_open(struct inode *inode, struct file *file)
935{
936 return seq_open(file, &rfcomm_seq_ops);
937} 906}
938 907
939static struct file_operations rfcomm_seq_fops = { 908static CLASS_ATTR(rfcomm, S_IRUGO, rfcomm_sock_sysfs_show, NULL);
940 .owner = THIS_MODULE,
941 .open = rfcomm_seq_open,
942 .read = seq_read,
943 .llseek = seq_lseek,
944 .release = seq_release,
945};
946
947static int __init rfcomm_sock_proc_init(void)
948{
949 struct proc_dir_entry *p = create_proc_entry("sock", S_IRUGO, proc_bt_rfcomm);
950 if (!p)
951 return -ENOMEM;
952 p->proc_fops = &rfcomm_seq_fops;
953 return 0;
954}
955
956static void __exit rfcomm_sock_proc_cleanup(void)
957{
958 remove_proc_entry("sock", proc_bt_rfcomm);
959}
960
961#else /* CONFIG_PROC_FS */
962
963static int __init rfcomm_sock_proc_init(void)
964{
965 return 0;
966}
967
968static void __exit rfcomm_sock_proc_cleanup(void)
969{
970 return;
971}
972#endif /* CONFIG_PROC_FS */
973 909
974static struct proto_ops rfcomm_sock_ops = { 910static struct proto_ops rfcomm_sock_ops = {
975 .family = PF_BLUETOOTH, 911 .family = PF_BLUETOOTH,
@@ -997,7 +933,7 @@ static struct net_proto_family rfcomm_sock_family_ops = {
997 .create = rfcomm_sock_create 933 .create = rfcomm_sock_create
998}; 934};
999 935
1000int __init rfcomm_init_sockets(void) 936int __init rfcomm_init_sockets(void)
1001{ 937{
1002 int err; 938 int err;
1003 939
@@ -1009,7 +945,7 @@ int __init rfcomm_init_sockets(void)
1009 if (err < 0) 945 if (err < 0)
1010 goto error; 946 goto error;
1011 947
1012 rfcomm_sock_proc_init(); 948 class_create_file(&bt_class, &class_attr_rfcomm);
1013 949
1014 BT_INFO("RFCOMM socket layer initialized"); 950 BT_INFO("RFCOMM socket layer initialized");
1015 951
@@ -1023,7 +959,7 @@ error:
1023 959
1024void __exit rfcomm_cleanup_sockets(void) 960void __exit rfcomm_cleanup_sockets(void)
1025{ 961{
1026 rfcomm_sock_proc_cleanup(); 962 class_remove_file(&bt_class, &class_attr_rfcomm);
1027 963
1028 if (bt_sock_unregister(BTPROTO_RFCOMM) < 0) 964 if (bt_sock_unregister(BTPROTO_RFCOMM) < 0)
1029 BT_ERR("RFCOMM socket layer unregistration failed"); 965 BT_ERR("RFCOMM socket layer unregistration failed");
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 997e42df115c..9cb00dc6c08c 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -38,8 +38,7 @@
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/socket.h> 39#include <linux/socket.h>
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <linux/proc_fs.h> 41#include <linux/device.h>
42#include <linux/seq_file.h>
43#include <linux/list.h> 42#include <linux/list.h>
44#include <net/sock.h> 43#include <net/sock.h>
45 44
@@ -55,7 +54,7 @@
55#define BT_DBG(D...) 54#define BT_DBG(D...)
56#endif 55#endif
57 56
58#define VERSION "0.4" 57#define VERSION "0.5"
59 58
60static struct proto_ops sco_sock_ops; 59static struct proto_ops sco_sock_ops;
61 60
@@ -893,91 +892,26 @@ drop:
893 return 0; 892 return 0;
894} 893}
895 894
896/* ---- Proc fs support ---- */ 895static ssize_t sco_sysfs_show(struct class *dev, char *buf)
897#ifdef CONFIG_PROC_FS
898static void *sco_seq_start(struct seq_file *seq, loff_t *pos)
899{ 896{
900 struct sock *sk; 897 struct sock *sk;
901 struct hlist_node *node; 898 struct hlist_node *node;
902 loff_t l = *pos; 899 char *str = buf;
903 900
904 read_lock_bh(&sco_sk_list.lock); 901 read_lock_bh(&sco_sk_list.lock);
905 902
906 sk_for_each(sk, node, &sco_sk_list.head) 903 sk_for_each(sk, node, &sco_sk_list.head) {
907 if (!l--) 904 str += sprintf(str, "%s %s %d\n",
908 goto found; 905 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst),
909 sk = NULL; 906 sk->sk_state);
910found: 907 }
911 return sk;
912}
913
914static void *sco_seq_next(struct seq_file *seq, void *e, loff_t *pos)
915{
916 struct sock *sk = e;
917 (*pos)++;
918 return sk_next(sk);
919}
920 908
921static void sco_seq_stop(struct seq_file *seq, void *e)
922{
923 read_unlock_bh(&sco_sk_list.lock); 909 read_unlock_bh(&sco_sk_list.lock);
924}
925
926static int sco_seq_show(struct seq_file *seq, void *e)
927{
928 struct sock *sk = e;
929 seq_printf(seq, "%s %s %d\n",
930 batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), sk->sk_state);
931 return 0;
932}
933 910
934static struct seq_operations sco_seq_ops = { 911 return (str - buf);
935 .start = sco_seq_start,
936 .next = sco_seq_next,
937 .stop = sco_seq_stop,
938 .show = sco_seq_show
939};
940
941static int sco_seq_open(struct inode *inode, struct file *file)
942{
943 return seq_open(file, &sco_seq_ops);
944} 912}
945 913
946static struct file_operations sco_seq_fops = { 914static CLASS_ATTR(sco, S_IRUGO, sco_sysfs_show, NULL);
947 .owner = THIS_MODULE,
948 .open = sco_seq_open,
949 .read = seq_read,
950 .llseek = seq_lseek,
951 .release = seq_release,
952};
953
954static int __init sco_proc_init(void)
955{
956 struct proc_dir_entry *p = create_proc_entry("sco", S_IRUGO, proc_bt);
957 if (!p)
958 return -ENOMEM;
959 p->owner = THIS_MODULE;
960 p->proc_fops = &sco_seq_fops;
961 return 0;
962}
963
964static void __exit sco_proc_cleanup(void)
965{
966 remove_proc_entry("sco", proc_bt);
967}
968
969#else /* CONFIG_PROC_FS */
970
971static int __init sco_proc_init(void)
972{
973 return 0;
974}
975
976static void __exit sco_proc_cleanup(void)
977{
978 return;
979}
980#endif /* CONFIG_PROC_FS */
981 915
982static struct proto_ops sco_sock_ops = { 916static struct proto_ops sco_sock_ops = {
983 .family = PF_BLUETOOTH, 917 .family = PF_BLUETOOTH,
@@ -1035,7 +969,7 @@ static int __init sco_init(void)
1035 goto error; 969 goto error;
1036 } 970 }
1037 971
1038 sco_proc_init(); 972 class_create_file(&bt_class, &class_attr_sco);
1039 973
1040 BT_INFO("SCO (Voice Link) ver %s", VERSION); 974 BT_INFO("SCO (Voice Link) ver %s", VERSION);
1041 BT_INFO("SCO socket layer initialized"); 975 BT_INFO("SCO socket layer initialized");
@@ -1049,7 +983,7 @@ error:
1049 983
1050static void __exit sco_exit(void) 984static void __exit sco_exit(void)
1051{ 985{
1052 sco_proc_cleanup(); 986 class_remove_file(&bt_class, &class_attr_sco);
1053 987
1054 if (bt_sock_unregister(BTPROTO_SCO) < 0) 988 if (bt_sock_unregister(BTPROTO_SCO) < 0)
1055 BT_ERR("SCO socket unregistration failed"); 989 BT_ERR("SCO socket unregistration failed");
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index db098ff3cd6a..cb530eef0e39 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -194,8 +194,7 @@ int dev_mc_add(struct net_device *dev, void *addr, int alen, int glbl)
194 194
195done: 195done:
196 spin_unlock_bh(&dev->xmit_lock); 196 spin_unlock_bh(&dev->xmit_lock);
197 if (dmi1) 197 kfree(dmi1);
198 kfree(dmi1);
199 return err; 198 return err;
200} 199}
201 200
diff --git a/net/core/sock.c b/net/core/sock.c
index 9602ceb3bac9..13cc3be4f056 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1242,8 +1242,7 @@ static void sock_def_write_space(struct sock *sk)
1242 1242
1243static void sock_def_destruct(struct sock *sk) 1243static void sock_def_destruct(struct sock *sk)
1244{ 1244{
1245 if (sk->sk_protinfo) 1245 kfree(sk->sk_protinfo);
1246 kfree(sk->sk_protinfo);
1247} 1246}
1248 1247
1249void sk_send_sigurg(struct sock *sk) 1248void sk_send_sigurg(struct sock *sk)
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 4b9bc81ae1a3..ca03521112c5 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -1263,10 +1263,8 @@ static int dccp_v4_destroy_sock(struct sock *sk)
1263 if (inet_csk(sk)->icsk_bind_hash != NULL) 1263 if (inet_csk(sk)->icsk_bind_hash != NULL)
1264 inet_put_port(&dccp_hashinfo, sk); 1264 inet_put_port(&dccp_hashinfo, sk);
1265 1265
1266 if (dp->dccps_service_list != NULL) { 1266 kfree(dp->dccps_service_list);
1267 kfree(dp->dccps_service_list); 1267 dp->dccps_service_list = NULL;
1268 dp->dccps_service_list = NULL;
1269 }
1270 1268
1271 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk); 1269 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
1272 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk); 1270 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index a021c3422f67..e0ace7cbb996 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -238,8 +238,7 @@ static int dccp_setsockopt_service(struct sock *sk, const u32 service,
238 lock_sock(sk); 238 lock_sock(sk);
239 dp->dccps_service = service; 239 dp->dccps_service = service;
240 240
241 if (dp->dccps_service_list != NULL) 241 kfree(dp->dccps_service_list);
242 kfree(dp->dccps_service_list);
243 242
244 dp->dccps_service_list = sl; 243 dp->dccps_service_list = sl;
245 release_sock(sk); 244 release_sock(sk);
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index eeba56f99323..6f8b5658cb4e 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -784,16 +784,14 @@ struct dn_fib_table *dn_fib_get_table(int n, int create)
784 784
785static void dn_fib_del_tree(int n) 785static void dn_fib_del_tree(int n)
786{ 786{
787 struct dn_fib_table *t; 787 struct dn_fib_table *t;
788 788
789 write_lock(&dn_fib_tables_lock); 789 write_lock(&dn_fib_tables_lock);
790 t = dn_fib_tables[n]; 790 t = dn_fib_tables[n];
791 dn_fib_tables[n] = NULL; 791 dn_fib_tables[n] = NULL;
792 write_unlock(&dn_fib_tables_lock); 792 write_unlock(&dn_fib_tables_lock);
793 793
794 if (t) { 794 kfree(t);
795 kfree(t);
796 }
797} 795}
798 796
799struct dn_fib_table *dn_fib_empty_table(void) 797struct dn_fib_table *dn_fib_empty_table(void)
diff --git a/net/ethernet/pe2.c b/net/ethernet/pe2.c
index 98a494be6039..9d57b4fb6440 100644
--- a/net/ethernet/pe2.c
+++ b/net/ethernet/pe2.c
@@ -32,8 +32,7 @@ struct datalink_proto *make_EII_client(void)
32 32
33void destroy_EII_client(struct datalink_proto *dl) 33void destroy_EII_client(struct datalink_proto *dl)
34{ 34{
35 if (dl) 35 kfree(dl);
36 kfree(dl);
37} 36}
38 37
39EXPORT_SYMBOL(destroy_EII_client); 38EXPORT_SYMBOL(destroy_EII_client);
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index a9d84f93442c..eaa150c33b04 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -147,8 +147,7 @@ void inet_sock_destruct(struct sock *sk)
147 BUG_TRAP(!sk->sk_wmem_queued); 147 BUG_TRAP(!sk->sk_wmem_queued);
148 BUG_TRAP(!sk->sk_forward_alloc); 148 BUG_TRAP(!sk->sk_forward_alloc);
149 149
150 if (inet->opt) 150 kfree(inet->opt);
151 kfree(inet->opt);
152 dst_release(sk->sk_dst_cache); 151 dst_release(sk->sk_dst_cache);
153 sk_refcnt_debug_dec(sk); 152 sk_refcnt_debug_dec(sk);
154} 153}
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 990633c09dfe..2267c1fad879 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -266,8 +266,7 @@ int ip_rt_ioctl(unsigned int cmd, void __user *arg)
266 if (tb) 266 if (tb)
267 err = tb->tb_insert(tb, &req.rtm, &rta, &req.nlh, NULL); 267 err = tb->tb_insert(tb, &req.rtm, &rta, &req.nlh, NULL);
268 } 268 }
269 if (rta.rta_mx) 269 kfree(rta.rta_mx);
270 kfree(rta.rta_mx);
271 } 270 }
272 rtnl_unlock(); 271 rtnl_unlock();
273 return err; 272 return err;
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
index bce4e875193b..dbe12da8d8b3 100644
--- a/net/ipv4/ip_options.c
+++ b/net/ipv4/ip_options.c
@@ -510,8 +510,7 @@ static int ip_options_get_finish(struct ip_options **optp,
510 kfree(opt); 510 kfree(opt);
511 return -EINVAL; 511 return -EINVAL;
512 } 512 }
513 if (*optp) 513 kfree(*optp);
514 kfree(*optp);
515 *optp = opt; 514 *optp = opt;
516 return 0; 515 return 0;
517} 516}
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 17758234a3e3..11c2f68254f0 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -353,7 +353,8 @@ packet_routed:
353 ip_options_build(skb, opt, inet->daddr, rt, 0); 353 ip_options_build(skb, opt, inet->daddr, rt, 0);
354 } 354 }
355 355
356 ip_select_ident_more(iph, &rt->u.dst, sk, skb_shinfo(skb)->tso_segs); 356 ip_select_ident_more(iph, &rt->u.dst, sk,
357 (skb_shinfo(skb)->tso_segs ?: 1) - 1);
357 358
358 /* Add an IP checksum. */ 359 /* Add an IP checksum. */
359 ip_send_check(iph); 360 ip_send_check(iph);
@@ -1262,10 +1263,8 @@ int ip_push_pending_frames(struct sock *sk)
1262 1263
1263out: 1264out:
1264 inet->cork.flags &= ~IPCORK_OPT; 1265 inet->cork.flags &= ~IPCORK_OPT;
1265 if (inet->cork.opt) { 1266 kfree(inet->cork.opt);
1266 kfree(inet->cork.opt); 1267 inet->cork.opt = NULL;
1267 inet->cork.opt = NULL;
1268 }
1269 if (inet->cork.rt) { 1268 if (inet->cork.rt) {
1270 ip_rt_put(inet->cork.rt); 1269 ip_rt_put(inet->cork.rt);
1271 inet->cork.rt = NULL; 1270 inet->cork.rt = NULL;
@@ -1289,10 +1288,8 @@ void ip_flush_pending_frames(struct sock *sk)
1289 kfree_skb(skb); 1288 kfree_skb(skb);
1290 1289
1291 inet->cork.flags &= ~IPCORK_OPT; 1290 inet->cork.flags &= ~IPCORK_OPT;
1292 if (inet->cork.opt) { 1291 kfree(inet->cork.opt);
1293 kfree(inet->cork.opt); 1292 inet->cork.opt = NULL;
1294 inet->cork.opt = NULL;
1295 }
1296 if (inet->cork.rt) { 1293 if (inet->cork.rt) {
1297 ip_rt_put(inet->cork.rt); 1294 ip_rt_put(inet->cork.rt);
1298 inet->cork.rt = NULL; 1295 inet->cork.rt = NULL;
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 2f0b47da5b37..4f2d87257309 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -202,8 +202,7 @@ int ip_ra_control(struct sock *sk, unsigned char on, void (*destructor)(struct s
202 if (ra->sk == sk) { 202 if (ra->sk == sk) {
203 if (on) { 203 if (on) {
204 write_unlock_bh(&ip_ra_lock); 204 write_unlock_bh(&ip_ra_lock);
205 if (new_ra) 205 kfree(new_ra);
206 kfree(new_ra);
207 return -EADDRINUSE; 206 return -EADDRINUSE;
208 } 207 }
209 *rap = ra->next; 208 *rap = ra->next;
@@ -446,8 +445,7 @@ int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
446#endif 445#endif
447 } 446 }
448 opt = xchg(&inet->opt, opt); 447 opt = xchg(&inet->opt, opt);
449 if (opt) 448 kfree(opt);
450 kfree(opt);
451 break; 449 break;
452 } 450 }
453 case IP_PKTINFO: 451 case IP_PKTINFO:
@@ -828,10 +826,8 @@ int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
828 826
829 err = ip_mc_msfilter(sk, msf, ifindex); 827 err = ip_mc_msfilter(sk, msf, ifindex);
830mc_msf_out: 828mc_msf_out:
831 if (msf) 829 kfree(msf);
832 kfree(msf); 830 kfree(gsf);
833 if (gsf)
834 kfree(gsf);
835 break; 831 break;
836 } 832 }
837 case IP_ROUTER_ALERT: 833 case IP_ROUTER_ALERT:
diff --git a/net/ipv4/ipvs/ip_vs_app.c b/net/ipv4/ipvs/ip_vs_app.c
index fc6f95aaa969..d7eb680101c2 100644
--- a/net/ipv4/ipvs/ip_vs_app.c
+++ b/net/ipv4/ipvs/ip_vs_app.c
@@ -110,8 +110,7 @@ ip_vs_app_inc_new(struct ip_vs_app *app, __u16 proto, __u16 port)
110 return 0; 110 return 0;
111 111
112 out: 112 out:
113 if (inc->timeout_table) 113 kfree(inc->timeout_table);
114 kfree(inc->timeout_table);
115 kfree(inc); 114 kfree(inc);
116 return ret; 115 return ret;
117} 116}
@@ -136,8 +135,7 @@ ip_vs_app_inc_release(struct ip_vs_app *inc)
136 135
137 list_del(&inc->a_list); 136 list_del(&inc->a_list);
138 137
139 if (inc->timeout_table != NULL) 138 kfree(inc->timeout_table);
140 kfree(inc->timeout_table);
141 kfree(inc); 139 kfree(inc);
142} 140}
143 141
diff --git a/net/ipv4/ipvs/ip_vs_core.c b/net/ipv4/ipvs/ip_vs_core.c
index 981cc3244ef2..1a0843cd58a9 100644
--- a/net/ipv4/ipvs/ip_vs_core.c
+++ b/net/ipv4/ipvs/ip_vs_core.c
@@ -1009,11 +1009,10 @@ ip_vs_in(unsigned int hooknum, struct sk_buff **pskb,
1009 if (sysctl_ip_vs_expire_nodest_conn) { 1009 if (sysctl_ip_vs_expire_nodest_conn) {
1010 /* try to expire the connection immediately */ 1010 /* try to expire the connection immediately */
1011 ip_vs_conn_expire_now(cp); 1011 ip_vs_conn_expire_now(cp);
1012 } else {
1013 /* don't restart its timer, and silently
1014 drop the packet. */
1015 __ip_vs_conn_put(cp);
1016 } 1012 }
1013 /* don't restart its timer, and silently
1014 drop the packet. */
1015 __ip_vs_conn_put(cp);
1017 return NF_DROP; 1016 return NF_DROP;
1018 } 1017 }
1019 1018
diff --git a/net/ipv4/multipath_wrandom.c b/net/ipv4/multipath_wrandom.c
index bd7d75b6abe0..d34a9fa608e0 100644
--- a/net/ipv4/multipath_wrandom.c
+++ b/net/ipv4/multipath_wrandom.c
@@ -207,16 +207,12 @@ static void wrandom_select_route(const struct flowi *flp,
207 decision = mpc->rt; 207 decision = mpc->rt;
208 208
209 last_power = mpc->power; 209 last_power = mpc->power;
210 if (last_mpc) 210 kfree(last_mpc);
211 kfree(last_mpc);
212
213 last_mpc = mpc; 211 last_mpc = mpc;
214 } 212 }
215 213
216 if (last_mpc) { 214 /* concurrent __multipath_flush may lead to !last_mpc */
217 /* concurrent __multipath_flush may lead to !last_mpc */ 215 kfree(last_mpc);
218 kfree(last_mpc);
219 }
220 216
221 decision->u.dst.__use++; 217 decision->u.dst.__use++;
222 *rp = decision; 218 *rp = decision;
diff --git a/net/ipv4/netfilter/ip_nat_snmp_basic.c b/net/ipv4/netfilter/ip_nat_snmp_basic.c
index 93b2c5111bb2..8acb7ed40b47 100644
--- a/net/ipv4/netfilter/ip_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/ip_nat_snmp_basic.c
@@ -1161,8 +1161,7 @@ static int snmp_parse_mangle(unsigned char *msg,
1161 1161
1162 if (!snmp_object_decode(&ctx, obj)) { 1162 if (!snmp_object_decode(&ctx, obj)) {
1163 if (*obj) { 1163 if (*obj) {
1164 if ((*obj)->id) 1164 kfree((*obj)->id);
1165 kfree((*obj)->id);
1166 kfree(*obj); 1165 kfree(*obj);
1167 } 1166 }
1168 kfree(obj); 1167 kfree(obj);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 49d67cd75edd..634dabb558fd 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -823,8 +823,7 @@ out:
823 */ 823 */
824static void tcp_v4_reqsk_destructor(struct request_sock *req) 824static void tcp_v4_reqsk_destructor(struct request_sock *req)
825{ 825{
826 if (inet_rsk(req)->opt) 826 kfree(inet_rsk(req)->opt);
827 kfree(inet_rsk(req)->opt);
828} 827}
829 828
830static inline void syn_flood_warning(struct sk_buff *skb) 829static inline void syn_flood_warning(struct sk_buff *skb)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 2c5f57299d63..b7a5f51238b3 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -35,6 +35,9 @@
35 * YOSHIFUJI Hideaki @USAGI : ARCnet support 35 * YOSHIFUJI Hideaki @USAGI : ARCnet support
36 * YOSHIFUJI Hideaki @USAGI : convert /proc/net/if_inet6 to 36 * YOSHIFUJI Hideaki @USAGI : convert /proc/net/if_inet6 to
37 * seq_file. 37 * seq_file.
38 * YOSHIFUJI Hideaki @USAGI : improved source address
39 * selection; consider scope,
40 * status etc.
38 */ 41 */
39 42
40#include <linux/config.h> 43#include <linux/config.h>
@@ -193,46 +196,51 @@ const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
193#endif 196#endif
194const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; 197const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
195 198
196int ipv6_addr_type(const struct in6_addr *addr) 199#define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
200
201static inline unsigned ipv6_addr_scope2type(unsigned scope)
202{
203 switch(scope) {
204 case IPV6_ADDR_SCOPE_NODELOCAL:
205 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL) |
206 IPV6_ADDR_LOOPBACK);
207 case IPV6_ADDR_SCOPE_LINKLOCAL:
208 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL) |
209 IPV6_ADDR_LINKLOCAL);
210 case IPV6_ADDR_SCOPE_SITELOCAL:
211 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL) |
212 IPV6_ADDR_SITELOCAL);
213 }
214 return IPV6_ADDR_SCOPE_TYPE(scope);
215}
216
217int __ipv6_addr_type(const struct in6_addr *addr)
197{ 218{
198 int type;
199 u32 st; 219 u32 st;
200 220
201 st = addr->s6_addr32[0]; 221 st = addr->s6_addr32[0];
202 222
203 if ((st & htonl(0xFF000000)) == htonl(0xFF000000)) {
204 type = IPV6_ADDR_MULTICAST;
205
206 switch((st & htonl(0x00FF0000))) {
207 case __constant_htonl(0x00010000):
208 type |= IPV6_ADDR_LOOPBACK;
209 break;
210
211 case __constant_htonl(0x00020000):
212 type |= IPV6_ADDR_LINKLOCAL;
213 break;
214
215 case __constant_htonl(0x00050000):
216 type |= IPV6_ADDR_SITELOCAL;
217 break;
218 };
219 return type;
220 }
221
222 type = IPV6_ADDR_UNICAST;
223
224 /* Consider all addresses with the first three bits different of 223 /* Consider all addresses with the first three bits different of
225 000 and 111 as finished. 224 000 and 111 as unicasts.
226 */ 225 */
227 if ((st & htonl(0xE0000000)) != htonl(0x00000000) && 226 if ((st & htonl(0xE0000000)) != htonl(0x00000000) &&
228 (st & htonl(0xE0000000)) != htonl(0xE0000000)) 227 (st & htonl(0xE0000000)) != htonl(0xE0000000))
229 return type; 228 return (IPV6_ADDR_UNICAST |
230 229 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL));
231 if ((st & htonl(0xFFC00000)) == htonl(0xFE800000)) 230
232 return (IPV6_ADDR_LINKLOCAL | type); 231 if ((st & htonl(0xFF000000)) == htonl(0xFF000000)) {
232 /* multicast */
233 /* addr-select 3.1 */
234 return (IPV6_ADDR_MULTICAST |
235 ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr)));
236 }
233 237
238 if ((st & htonl(0xFFC00000)) == htonl(0xFE800000))
239 return (IPV6_ADDR_LINKLOCAL | IPV6_ADDR_UNICAST |
240 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL)); /* addr-select 3.1 */
234 if ((st & htonl(0xFFC00000)) == htonl(0xFEC00000)) 241 if ((st & htonl(0xFFC00000)) == htonl(0xFEC00000))
235 return (IPV6_ADDR_SITELOCAL | type); 242 return (IPV6_ADDR_SITELOCAL | IPV6_ADDR_UNICAST |
243 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL)); /* addr-select 3.1 */
236 244
237 if ((addr->s6_addr32[0] | addr->s6_addr32[1]) == 0) { 245 if ((addr->s6_addr32[0] | addr->s6_addr32[1]) == 0) {
238 if (addr->s6_addr32[2] == 0) { 246 if (addr->s6_addr32[2] == 0) {
@@ -240,24 +248,20 @@ int ipv6_addr_type(const struct in6_addr *addr)
240 return IPV6_ADDR_ANY; 248 return IPV6_ADDR_ANY;
241 249
242 if (addr->s6_addr32[3] == htonl(0x00000001)) 250 if (addr->s6_addr32[3] == htonl(0x00000001))
243 return (IPV6_ADDR_LOOPBACK | type); 251 return (IPV6_ADDR_LOOPBACK | IPV6_ADDR_UNICAST |
252 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL)); /* addr-select 3.4 */
244 253
245 return (IPV6_ADDR_COMPATv4 | type); 254 return (IPV6_ADDR_COMPATv4 | IPV6_ADDR_UNICAST |
255 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.3 */
246 } 256 }
247 257
248 if (addr->s6_addr32[2] == htonl(0x0000ffff)) 258 if (addr->s6_addr32[2] == htonl(0x0000ffff))
249 return IPV6_ADDR_MAPPED; 259 return (IPV6_ADDR_MAPPED |
260 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.3 */
250 } 261 }
251 262
252 st &= htonl(0xFF000000); 263 return (IPV6_ADDR_RESERVED |
253 if (st == 0) 264 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.4 */
254 return IPV6_ADDR_RESERVED;
255 st &= htonl(0xFE000000);
256 if (st == htonl(0x02000000))
257 return IPV6_ADDR_RESERVED; /* for NSAP */
258 if (st == htonl(0x04000000))
259 return IPV6_ADDR_RESERVED; /* for IPX */
260 return type;
261} 265}
262 266
263static void addrconf_del_timer(struct inet6_ifaddr *ifp) 267static void addrconf_del_timer(struct inet6_ifaddr *ifp)
@@ -805,138 +809,274 @@ out:
805#endif 809#endif
806 810
807/* 811/*
808 * Choose an appropriate source address 812 * Choose an appropriate source address (RFC3484)
809 * should do:
810 * i) get an address with an appropriate scope
811 * ii) see if there is a specific route for the destination and use
812 * an address of the attached interface
813 * iii) don't use deprecated addresses
814 */ 813 */
815static int inline ipv6_saddr_pref(const struct inet6_ifaddr *ifp, u8 invpref) 814struct ipv6_saddr_score {
815 int addr_type;
816 unsigned int attrs;
817 int matchlen;
818 unsigned int scope;
819 unsigned int rule;
820};
821
822#define IPV6_SADDR_SCORE_LOCAL 0x0001
823#define IPV6_SADDR_SCORE_PREFERRED 0x0004
824#define IPV6_SADDR_SCORE_HOA 0x0008
825#define IPV6_SADDR_SCORE_OIF 0x0010
826#define IPV6_SADDR_SCORE_LABEL 0x0020
827#define IPV6_SADDR_SCORE_PRIVACY 0x0040
828
829static int inline ipv6_saddr_preferred(int type)
816{ 830{
817 int pref; 831 if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|
818 pref = ifp->flags&IFA_F_DEPRECATED ? 0 : 2; 832 IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED))
819#ifdef CONFIG_IPV6_PRIVACY 833 return 1;
820 pref |= (ifp->flags^invpref)&IFA_F_TEMPORARY ? 0 : 1; 834 return 0;
821#endif
822 return pref;
823} 835}
824 836
825#ifdef CONFIG_IPV6_PRIVACY 837/* static matching label */
826#define IPV6_GET_SADDR_MAXSCORE(score) ((score) == 3) 838static int inline ipv6_saddr_label(const struct in6_addr *addr, int type)
827#else 839{
828#define IPV6_GET_SADDR_MAXSCORE(score) (score) 840 /*
829#endif 841 * prefix (longest match) label
842 * -----------------------------
843 * ::1/128 0
844 * ::/0 1
845 * 2002::/16 2
846 * ::/96 3
847 * ::ffff:0:0/96 4
848 */
849 if (type & IPV6_ADDR_LOOPBACK)
850 return 0;
851 else if (type & IPV6_ADDR_COMPATv4)
852 return 3;
853 else if (type & IPV6_ADDR_MAPPED)
854 return 4;
855 else if (addr->s6_addr16[0] == htons(0x2002))
856 return 2;
857 return 1;
858}
830 859
831int ipv6_dev_get_saddr(struct net_device *dev, 860int ipv6_dev_get_saddr(struct net_device *daddr_dev,
832 struct in6_addr *daddr, struct in6_addr *saddr) 861 struct in6_addr *daddr, struct in6_addr *saddr)
833{ 862{
834 struct inet6_ifaddr *ifp = NULL; 863 struct ipv6_saddr_score hiscore;
835 struct inet6_ifaddr *match = NULL; 864 struct inet6_ifaddr *ifa_result = NULL;
836 struct inet6_dev *idev; 865 int daddr_type = __ipv6_addr_type(daddr);
837 int scope; 866 int daddr_scope = __ipv6_addr_src_scope(daddr_type);
838 int err; 867 u32 daddr_label = ipv6_saddr_label(daddr, daddr_type);
839 int hiscore = -1, score; 868 struct net_device *dev;
840 869
841 scope = ipv6_addr_scope(daddr); 870 memset(&hiscore, 0, sizeof(hiscore));
842 871
843 /* 872 read_lock(&dev_base_lock);
844 * known dev 873 read_lock(&addrconf_lock);
845 * search dev and walk through dev addresses
846 */
847 874
848 if (dev) { 875 for (dev = dev_base; dev; dev=dev->next) {
849 if (dev->flags & IFF_LOOPBACK) 876 struct inet6_dev *idev;
850 scope = IFA_HOST; 877 struct inet6_ifaddr *ifa;
878
879 /* Rule 0: Candidate Source Address (section 4)
880 * - multicast and link-local destination address,
881 * the set of candidate source address MUST only
882 * include addresses assigned to interfaces
883 * belonging to the same link as the outgoing
884 * interface.
885 * (- For site-local destination addresses, the
886 * set of candidate source addresses MUST only
887 * include addresses assigned to interfaces
888 * belonging to the same site as the outgoing
889 * interface.)
890 */
891 if ((daddr_type & IPV6_ADDR_MULTICAST ||
892 daddr_scope <= IPV6_ADDR_SCOPE_LINKLOCAL) &&
893 daddr_dev && dev != daddr_dev)
894 continue;
851 895
852 read_lock(&addrconf_lock);
853 idev = __in6_dev_get(dev); 896 idev = __in6_dev_get(dev);
854 if (idev) { 897 if (!idev)
855 read_lock_bh(&idev->lock); 898 continue;
856 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
857 if (ifp->scope == scope) {
858 if (ifp->flags&IFA_F_TENTATIVE)
859 continue;
860#ifdef CONFIG_IPV6_PRIVACY
861 score = ipv6_saddr_pref(ifp, idev->cnf.use_tempaddr > 1 ? IFA_F_TEMPORARY : 0);
862#else
863 score = ipv6_saddr_pref(ifp, 0);
864#endif
865 if (score <= hiscore)
866 continue;
867 899
868 if (match) 900 read_lock_bh(&idev->lock);
869 in6_ifa_put(match); 901 for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) {
870 match = ifp; 902 struct ipv6_saddr_score score;
871 hiscore = score;
872 in6_ifa_hold(ifp);
873 903
874 if (IPV6_GET_SADDR_MAXSCORE(score)) { 904 score.addr_type = __ipv6_addr_type(&ifa->addr);
875 read_unlock_bh(&idev->lock); 905
876 read_unlock(&addrconf_lock); 906 /* Rule 0: Candidate Source Address (section 4)
877 goto out; 907 * - In any case, anycast addresses, multicast
878 } 908 * addresses, and the unspecified address MUST
909 * NOT be included in a candidate set.
910 */
911 if (unlikely(score.addr_type == IPV6_ADDR_ANY ||
912 score.addr_type & IPV6_ADDR_MULTICAST)) {
913 LIMIT_NETDEBUG(KERN_DEBUG
914 "ADDRCONF: unspecified / multicast address"
915 "assigned as unicast address on %s",
916 dev->name);
917 continue;
918 }
919
920 score.attrs = 0;
921 score.matchlen = 0;
922 score.scope = 0;
923 score.rule = 0;
924
925 if (ifa_result == NULL) {
926 /* record it if the first available entry */
927 goto record_it;
928 }
929
930 /* Rule 1: Prefer same address */
931 if (hiscore.rule < 1) {
932 if (ipv6_addr_equal(&ifa_result->addr, daddr))
933 hiscore.attrs |= IPV6_SADDR_SCORE_LOCAL;
934 hiscore.rule++;
935 }
936 if (ipv6_addr_equal(&ifa->addr, daddr)) {
937 score.attrs |= IPV6_SADDR_SCORE_LOCAL;
938 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)) {
939 score.rule = 1;
940 goto record_it;
879 } 941 }
942 } else {
943 if (hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)
944 continue;
880 } 945 }
881 read_unlock_bh(&idev->lock);
882 }
883 read_unlock(&addrconf_lock);
884 }
885 946
886 if (scope == IFA_LINK) 947 /* Rule 2: Prefer appropriate scope */
887 goto out; 948 if (hiscore.rule < 2) {
949 hiscore.scope = __ipv6_addr_src_scope(hiscore.addr_type);
950 hiscore.rule++;
951 }
952 score.scope = __ipv6_addr_src_scope(score.addr_type);
953 if (hiscore.scope < score.scope) {
954 if (hiscore.scope < daddr_scope) {
955 score.rule = 2;
956 goto record_it;
957 } else
958 continue;
959 } else if (score.scope < hiscore.scope) {
960 if (score.scope < daddr_scope)
961 continue;
962 else {
963 score.rule = 2;
964 goto record_it;
965 }
966 }
888 967
889 /* 968 /* Rule 3: Avoid deprecated address */
890 * dev == NULL or search failed for specified dev 969 if (hiscore.rule < 3) {
891 */ 970 if (ipv6_saddr_preferred(hiscore.addr_type) ||
971 !(ifa_result->flags & IFA_F_DEPRECATED))
972 hiscore.attrs |= IPV6_SADDR_SCORE_PREFERRED;
973 hiscore.rule++;
974 }
975 if (ipv6_saddr_preferred(score.addr_type) ||
976 !(ifa->flags & IFA_F_DEPRECATED)) {
977 score.attrs |= IPV6_SADDR_SCORE_PREFERRED;
978 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)) {
979 score.rule = 3;
980 goto record_it;
981 }
982 } else {
983 if (hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)
984 continue;
985 }
892 986
893 read_lock(&dev_base_lock); 987 /* Rule 4: Prefer home address -- not implemented yet */
894 read_lock(&addrconf_lock);
895 for (dev = dev_base; dev; dev=dev->next) {
896 idev = __in6_dev_get(dev);
897 if (idev) {
898 read_lock_bh(&idev->lock);
899 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
900 if (ifp->scope == scope) {
901 if (ifp->flags&IFA_F_TENTATIVE)
902 continue;
903#ifdef CONFIG_IPV6_PRIVACY
904 score = ipv6_saddr_pref(ifp, idev->cnf.use_tempaddr > 1 ? IFA_F_TEMPORARY : 0);
905#else
906 score = ipv6_saddr_pref(ifp, 0);
907#endif
908 if (score <= hiscore)
909 continue;
910 988
911 if (match) 989 /* Rule 5: Prefer outgoing interface */
912 in6_ifa_put(match); 990 if (hiscore.rule < 5) {
913 match = ifp; 991 if (daddr_dev == NULL ||
914 hiscore = score; 992 daddr_dev == ifa_result->idev->dev)
915 in6_ifa_hold(ifp); 993 hiscore.attrs |= IPV6_SADDR_SCORE_OIF;
994 hiscore.rule++;
995 }
996 if (daddr_dev == NULL ||
997 daddr_dev == ifa->idev->dev) {
998 score.attrs |= IPV6_SADDR_SCORE_OIF;
999 if (!(hiscore.attrs & IPV6_SADDR_SCORE_OIF)) {
1000 score.rule = 5;
1001 goto record_it;
1002 }
1003 } else {
1004 if (hiscore.attrs & IPV6_SADDR_SCORE_OIF)
1005 continue;
1006 }
916 1007
917 if (IPV6_GET_SADDR_MAXSCORE(score)) { 1008 /* Rule 6: Prefer matching label */
918 read_unlock_bh(&idev->lock); 1009 if (hiscore.rule < 6) {
919 goto out_unlock_base; 1010 if (ipv6_saddr_label(&ifa_result->addr, hiscore.addr_type) == daddr_label)
920 } 1011 hiscore.attrs |= IPV6_SADDR_SCORE_LABEL;
1012 hiscore.rule++;
1013 }
1014 if (ipv6_saddr_label(&ifa->addr, score.addr_type) == daddr_label) {
1015 score.attrs |= IPV6_SADDR_SCORE_LABEL;
1016 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LABEL)) {
1017 score.rule = 6;
1018 goto record_it;
1019 }
1020 } else {
1021 if (hiscore.attrs & IPV6_SADDR_SCORE_LABEL)
1022 continue;
1023 }
1024
1025 /* Rule 7: Prefer public address
1026 * Note: prefer temprary address if use_tempaddr >= 2
1027 */
1028 if (hiscore.rule < 7) {
1029 if ((!(ifa_result->flags & IFA_F_TEMPORARY)) ^
1030 (ifa_result->idev->cnf.use_tempaddr >= 2))
1031 hiscore.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1032 hiscore.rule++;
1033 }
1034 if ((!(ifa->flags & IFA_F_TEMPORARY)) ^
1035 (ifa->idev->cnf.use_tempaddr >= 2)) {
1036 score.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1037 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)) {
1038 score.rule = 7;
1039 goto record_it;
921 } 1040 }
1041 } else {
1042 if (hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)
1043 continue;
922 } 1044 }
923 read_unlock_bh(&idev->lock); 1045
1046 /* Rule 8: Use longest matching prefix */
1047 if (hiscore.rule < 8)
1048 hiscore.matchlen = ipv6_addr_diff(&ifa_result->addr, daddr);
1049 score.rule++;
1050 score.matchlen = ipv6_addr_diff(&ifa->addr, daddr);
1051 if (score.matchlen > hiscore.matchlen) {
1052 score.rule = 8;
1053 goto record_it;
1054 }
1055#if 0
1056 else if (score.matchlen < hiscore.matchlen)
1057 continue;
1058#endif
1059
1060 /* Final Rule: choose first available one */
1061 continue;
1062record_it:
1063 if (ifa_result)
1064 in6_ifa_put(ifa_result);
1065 in6_ifa_hold(ifa);
1066 ifa_result = ifa;
1067 hiscore = score;
924 } 1068 }
1069 read_unlock_bh(&idev->lock);
925 } 1070 }
926
927out_unlock_base:
928 read_unlock(&addrconf_lock); 1071 read_unlock(&addrconf_lock);
929 read_unlock(&dev_base_lock); 1072 read_unlock(&dev_base_lock);
930 1073
931out: 1074 if (!ifa_result)
932 err = -EADDRNOTAVAIL; 1075 return -EADDRNOTAVAIL;
933 if (match) { 1076
934 ipv6_addr_copy(saddr, &match->addr); 1077 ipv6_addr_copy(saddr, &ifa_result->addr);
935 err = 0; 1078 in6_ifa_put(ifa_result);
936 in6_ifa_put(match); 1079 return 0;
937 }
938
939 return err;
940} 1080}
941 1081
942 1082
@@ -2950,8 +3090,7 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
2950 3090
2951nlmsg_failure: 3091nlmsg_failure:
2952rtattr_failure: 3092rtattr_failure:
2953 if (array) 3093 kfree(array);
2954 kfree(array);
2955 skb_trim(skb, b - skb->data); 3094 skb_trim(skb, b - skb->data);
2956 return -1; 3095 return -1;
2957} 3096}
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 4fcc5a7acf6e..1bf6d9a769e6 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -127,56 +127,6 @@ static __inline__ int addr_bit_set(void *token, int fn_bit)
127 return htonl(1 << ((~fn_bit)&0x1F)) & addr[fn_bit>>5]; 127 return htonl(1 << ((~fn_bit)&0x1F)) & addr[fn_bit>>5];
128} 128}
129 129
130/*
131 * find the first different bit between two addresses
132 * length of address must be a multiple of 32bits
133 */
134
135static __inline__ int addr_diff(void *token1, void *token2, int addrlen)
136{
137 __u32 *a1 = token1;
138 __u32 *a2 = token2;
139 int i;
140
141 addrlen >>= 2;
142
143 for (i = 0; i < addrlen; i++) {
144 __u32 xb;
145
146 xb = a1[i] ^ a2[i];
147
148 if (xb) {
149 int j = 31;
150
151 xb = ntohl(xb);
152
153 while ((xb & (1 << j)) == 0)
154 j--;
155
156 return (i * 32 + 31 - j);
157 }
158 }
159
160 /*
161 * we should *never* get to this point since that
162 * would mean the addrs are equal
163 *
164 * However, we do get to it 8) And exacly, when
165 * addresses are equal 8)
166 *
167 * ip route add 1111::/128 via ...
168 * ip route add 1111::/64 via ...
169 * and we are here.
170 *
171 * Ideally, this function should stop comparison
172 * at prefix length. It does not, but it is still OK,
173 * if returned value is greater than prefix length.
174 * --ANK (980803)
175 */
176
177 return addrlen<<5;
178}
179
180static __inline__ struct fib6_node * node_alloc(void) 130static __inline__ struct fib6_node * node_alloc(void)
181{ 131{
182 struct fib6_node *fn; 132 struct fib6_node *fn;
@@ -296,11 +246,11 @@ insert_above:
296 246
297 /* find 1st bit in difference between the 2 addrs. 247 /* find 1st bit in difference between the 2 addrs.
298 248
299 See comment in addr_diff: bit may be an invalid value, 249 See comment in __ipv6_addr_diff: bit may be an invalid value,
300 but if it is >= plen, the value is ignored in any case. 250 but if it is >= plen, the value is ignored in any case.
301 */ 251 */
302 252
303 bit = addr_diff(addr, &key->addr, addrlen); 253 bit = __ipv6_addr_diff(addr, &key->addr, addrlen);
304 254
305 /* 255 /*
306 * (intermediate)[in] 256 * (intermediate)[in]
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 614296a920c6..dbd9767b32e4 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -587,8 +587,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
587 skb->next = NULL; 587 skb->next = NULL;
588 } 588 }
589 589
590 if (tmp_hdr) 590 kfree(tmp_hdr);
591 kfree(tmp_hdr);
592 591
593 if (err == 0) { 592 if (err == 0) {
594 IP6_INC_STATS(IPSTATS_MIB_FRAGOKS); 593 IP6_INC_STATS(IPSTATS_MIB_FRAGOKS);
@@ -1186,10 +1185,8 @@ int ip6_push_pending_frames(struct sock *sk)
1186 1185
1187out: 1186out:
1188 inet->cork.flags &= ~IPCORK_OPT; 1187 inet->cork.flags &= ~IPCORK_OPT;
1189 if (np->cork.opt) { 1188 kfree(np->cork.opt);
1190 kfree(np->cork.opt); 1189 np->cork.opt = NULL;
1191 np->cork.opt = NULL;
1192 }
1193 if (np->cork.rt) { 1190 if (np->cork.rt) {
1194 dst_release(&np->cork.rt->u.dst); 1191 dst_release(&np->cork.rt->u.dst);
1195 np->cork.rt = NULL; 1192 np->cork.rt = NULL;
@@ -1214,10 +1211,8 @@ void ip6_flush_pending_frames(struct sock *sk)
1214 1211
1215 inet->cork.flags &= ~IPCORK_OPT; 1212 inet->cork.flags &= ~IPCORK_OPT;
1216 1213
1217 if (np->cork.opt) { 1214 kfree(np->cork.opt);
1218 kfree(np->cork.opt); 1215 np->cork.opt = NULL;
1219 np->cork.opt = NULL;
1220 }
1221 if (np->cork.rt) { 1216 if (np->cork.rt) {
1222 dst_release(&np->cork.rt->u.dst); 1217 dst_release(&np->cork.rt->u.dst);
1223 np->cork.rt = NULL; 1218 np->cork.rt = NULL;
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index cf94372d1af3..e6b0e3954c02 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -756,8 +756,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
756 } 756 }
757 ip6_tnl_dst_store(t, dst); 757 ip6_tnl_dst_store(t, dst);
758 758
759 if (opt) 759 kfree(opt);
760 kfree(opt);
761 760
762 t->recursion--; 761 t->recursion--;
763 return 0; 762 return 0;
@@ -766,8 +765,7 @@ tx_err_link_failure:
766 dst_link_failure(skb); 765 dst_link_failure(skb);
767tx_err_dst_release: 766tx_err_dst_release:
768 dst_release(dst); 767 dst_release(dst);
769 if (opt) 768 kfree(opt);
770 kfree(opt);
771tx_err: 769tx_err:
772 stats->tx_errors++; 770 stats->tx_errors++;
773 stats->tx_dropped++; 771 stats->tx_dropped++;
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c
index 85bfbc69b2c3..55917fb17094 100644
--- a/net/ipv6/ipcomp6.c
+++ b/net/ipv6/ipcomp6.c
@@ -130,8 +130,7 @@ static int ipcomp6_input(struct xfrm_state *x, struct xfrm_decap_state *decap, s
130out_put_cpu: 130out_put_cpu:
131 put_cpu(); 131 put_cpu();
132out: 132out:
133 if (tmp_hdr) 133 kfree(tmp_hdr);
134 kfree(tmp_hdr);
135 if (err) 134 if (err)
136 goto error_out; 135 goto error_out;
137 return nexthdr; 136 return nexthdr;
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 8567873d0dd8..003fd99ff597 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -80,8 +80,7 @@ int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
80 if (ra->sk == sk) { 80 if (ra->sk == sk) {
81 if (sel>=0) { 81 if (sel>=0) {
82 write_unlock_bh(&ip6_ra_lock); 82 write_unlock_bh(&ip6_ra_lock);
83 if (new_ra) 83 kfree(new_ra);
84 kfree(new_ra);
85 return -EADDRINUSE; 84 return -EADDRINUSE;
86 } 85 }
87 86
diff --git a/net/ipv6/ipv6_syms.c b/net/ipv6/ipv6_syms.c
index 37a4a99c9fe9..16482785bdfd 100644
--- a/net/ipv6/ipv6_syms.c
+++ b/net/ipv6/ipv6_syms.c
@@ -7,7 +7,7 @@
7#include <net/ip6_route.h> 7#include <net/ip6_route.h>
8#include <net/xfrm.h> 8#include <net/xfrm.h>
9 9
10EXPORT_SYMBOL(ipv6_addr_type); 10EXPORT_SYMBOL(__ipv6_addr_type);
11EXPORT_SYMBOL(icmpv6_send); 11EXPORT_SYMBOL(icmpv6_send);
12EXPORT_SYMBOL(icmpv6_statistics); 12EXPORT_SYMBOL(icmpv6_statistics);
13EXPORT_SYMBOL(icmpv6_err_convert); 13EXPORT_SYMBOL(icmpv6_err_convert);
diff --git a/net/irda/discovery.c b/net/irda/discovery.c
index c4ba5fa1446a..3fefc822c1c0 100644
--- a/net/irda/discovery.c
+++ b/net/irda/discovery.c
@@ -194,8 +194,7 @@ void irlmp_expire_discoveries(hashbin_t *log, __u32 saddr, int force)
194 194
195 /* Remove it from the log */ 195 /* Remove it from the log */
196 curr = hashbin_remove_this(log, (irda_queue_t *) curr); 196 curr = hashbin_remove_this(log, (irda_queue_t *) curr);
197 if (curr) 197 kfree(curr);
198 kfree(curr);
199 } 198 }
200 } 199 }
201 200
diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c
index 6fec428b4512..75f2666e8630 100644
--- a/net/irda/irias_object.c
+++ b/net/irda/irias_object.c
@@ -122,8 +122,7 @@ static void __irias_delete_attrib(struct ias_attrib *attrib)
122 IRDA_ASSERT(attrib != NULL, return;); 122 IRDA_ASSERT(attrib != NULL, return;);
123 IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return;); 123 IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return;);
124 124
125 if (attrib->name) 125 kfree(attrib->name);
126 kfree(attrib->name);
127 126
128 irias_delete_value(attrib->value); 127 irias_delete_value(attrib->value);
129 attrib->magic = ~IAS_ATTRIB_MAGIC; 128 attrib->magic = ~IAS_ATTRIB_MAGIC;
@@ -136,8 +135,7 @@ void __irias_delete_object(struct ias_object *obj)
136 IRDA_ASSERT(obj != NULL, return;); 135 IRDA_ASSERT(obj != NULL, return;);
137 IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;); 136 IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
138 137
139 if (obj->name) 138 kfree(obj->name);
140 kfree(obj->name);
141 139
142 hashbin_delete(obj->attribs, (FREE_FUNC) __irias_delete_attrib); 140 hashbin_delete(obj->attribs, (FREE_FUNC) __irias_delete_attrib);
143 141
@@ -562,14 +560,12 @@ void irias_delete_value(struct ias_value *value)
562 /* No need to deallocate */ 560 /* No need to deallocate */
563 break; 561 break;
564 case IAS_STRING: 562 case IAS_STRING:
565 /* If string, deallocate string */ 563 /* Deallocate string */
566 if (value->t.string != NULL) 564 kfree(value->t.string);
567 kfree(value->t.string);
568 break; 565 break;
569 case IAS_OCT_SEQ: 566 case IAS_OCT_SEQ:
570 /* If byte stream, deallocate byte stream */ 567 /* Deallocate byte stream */
571 if (value->t.oct_seq != NULL) 568 kfree(value->t.oct_seq);
572 kfree(value->t.oct_seq);
573 break; 569 break;
574 default: 570 default:
575 IRDA_DEBUG(0, "%s(), Unknown value type!\n", __FUNCTION__); 571 IRDA_DEBUG(0, "%s(), Unknown value type!\n", __FUNCTION__);
diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c
index b18fe5043019..8631b65a7312 100644
--- a/net/rose/rose_route.c
+++ b/net/rose/rose_route.c
@@ -240,8 +240,7 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
240 if ((s = rose_neigh_list) == rose_neigh) { 240 if ((s = rose_neigh_list) == rose_neigh) {
241 rose_neigh_list = rose_neigh->next; 241 rose_neigh_list = rose_neigh->next;
242 spin_unlock_bh(&rose_neigh_list_lock); 242 spin_unlock_bh(&rose_neigh_list_lock);
243 if (rose_neigh->digipeat != NULL) 243 kfree(rose_neigh->digipeat);
244 kfree(rose_neigh->digipeat);
245 kfree(rose_neigh); 244 kfree(rose_neigh);
246 return; 245 return;
247 } 246 }
@@ -250,8 +249,7 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
250 if (s->next == rose_neigh) { 249 if (s->next == rose_neigh) {
251 s->next = rose_neigh->next; 250 s->next = rose_neigh->next;
252 spin_unlock_bh(&rose_neigh_list_lock); 251 spin_unlock_bh(&rose_neigh_list_lock);
253 if (rose_neigh->digipeat != NULL) 252 kfree(rose_neigh->digipeat);
254 kfree(rose_neigh->digipeat);
255 kfree(rose_neigh); 253 kfree(rose_neigh);
256 return; 254 return;
257 } 255 }
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 29d8b9a4d162..75470486e405 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -298,8 +298,7 @@ static int fw_change(struct tcf_proto *tp, unsigned long base,
298 return 0; 298 return 0;
299 299
300errout: 300errout:
301 if (f) 301 kfree(f);
302 kfree(f);
303 return err; 302 return err;
304} 303}
305 304
diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c
index 02996ac05c75..520ff716dab2 100644
--- a/net/sched/cls_route.c
+++ b/net/sched/cls_route.c
@@ -525,8 +525,7 @@ reinsert:
525 return 0; 525 return 0;
526 526
527errout: 527errout:
528 if (f) 528 kfree(f);
529 kfree(f);
530 return err; 529 return err;
531} 530}
532 531
diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 006168d69376..572f06be3b02 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -555,8 +555,7 @@ insert:
555 goto insert; 555 goto insert;
556 556
557errout: 557errout:
558 if (f) 558 kfree(f);
559 kfree(f);
560errout2: 559errout2:
561 tcf_exts_destroy(tp, &e); 560 tcf_exts_destroy(tp, &e);
562 return err; 561 return err;
diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c
index 404d9d83a7fa..9f921174c8ab 100644
--- a/net/sched/cls_tcindex.c
+++ b/net/sched/cls_tcindex.c
@@ -194,8 +194,7 @@ found:
194 } 194 }
195 tcf_unbind_filter(tp, &r->res); 195 tcf_unbind_filter(tp, &r->res);
196 tcf_exts_destroy(tp, &r->exts); 196 tcf_exts_destroy(tp, &r->exts);
197 if (f) 197 kfree(f);
198 kfree(f);
199 return 0; 198 return 0;
200} 199}
201 200
@@ -442,10 +441,8 @@ static void tcindex_destroy(struct tcf_proto *tp)
442 walker.skip = 0; 441 walker.skip = 0;
443 walker.fn = &tcindex_destroy_element; 442 walker.fn = &tcindex_destroy_element;
444 tcindex_walk(tp,&walker); 443 tcindex_walk(tp,&walker);
445 if (p->perfect) 444 kfree(p->perfect);
446 kfree(p->perfect); 445 kfree(p->h);
447 if (p->h)
448 kfree(p->h);
449 kfree(p); 446 kfree(p);
450 tp->root = NULL; 447 tp->root = NULL;
451} 448}
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 364b87d86455..2b670479dde1 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -347,7 +347,7 @@ static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)
347 if (n->ht_down) 347 if (n->ht_down)
348 n->ht_down->refcnt--; 348 n->ht_down->refcnt--;
349#ifdef CONFIG_CLS_U32_PERF 349#ifdef CONFIG_CLS_U32_PERF
350 if (n && (NULL != n->pf)) 350 if (n)
351 kfree(n->pf); 351 kfree(n->pf);
352#endif 352#endif
353 kfree(n); 353 kfree(n);
@@ -680,7 +680,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
680 return 0; 680 return 0;
681 } 681 }
682#ifdef CONFIG_CLS_U32_PERF 682#ifdef CONFIG_CLS_U32_PERF
683 if (n && (NULL != n->pf)) 683 if (n)
684 kfree(n->pf); 684 kfree(n->pf);
685#endif 685#endif
686 kfree(n); 686 kfree(n);
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index cf68a59fdc5a..700844d49d79 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -561,8 +561,7 @@ static int meta_var_change(struct meta_value *dst, struct rtattr *rta)
561 561
562static void meta_var_destroy(struct meta_value *v) 562static void meta_var_destroy(struct meta_value *v)
563{ 563{
564 if (v->val) 564 kfree((void *) v->val);
565 kfree((void *) v->val);
566} 565}
567 566
568static void meta_var_apply_extras(struct meta_value *v, 567static void meta_var_apply_extras(struct meta_value *v,
diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index ebfe2e7d21bd..64b047c65568 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -298,6 +298,11 @@ int tcf_em_tree_validate(struct tcf_proto *tp, struct rtattr *rta,
298 struct tcf_ematch_tree_hdr *tree_hdr; 298 struct tcf_ematch_tree_hdr *tree_hdr;
299 struct tcf_ematch *em; 299 struct tcf_ematch *em;
300 300
301 if (!rta) {
302 memset(tree, 0, sizeof(*tree));
303 return 0;
304 }
305
301 if (rtattr_parse_nested(tb, TCA_EMATCH_TREE_MAX, rta) < 0) 306 if (rtattr_parse_nested(tb, TCA_EMATCH_TREE_MAX, rta) < 0)
302 goto errout; 307 goto errout;
303 308
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 12b0f582a66b..8c8ddf7f9b61 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -344,9 +344,7 @@ void sctp_association_free(struct sctp_association *asoc)
344 } 344 }
345 345
346 /* Free peer's cached cookie. */ 346 /* Free peer's cached cookie. */
347 if (asoc->peer.cookie) { 347 kfree(asoc->peer.cookie);
348 kfree(asoc->peer.cookie);
349 }
350 348
351 /* Release the transport structures. */ 349 /* Release the transport structures. */
352 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { 350 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 660c61bdf164..f9573eba5c7a 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -254,8 +254,7 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
254 aiparam.adaption_ind = htonl(sp->adaption_ind); 254 aiparam.adaption_ind = htonl(sp->adaption_ind);
255 sctp_addto_chunk(retval, sizeof(aiparam), &aiparam); 255 sctp_addto_chunk(retval, sizeof(aiparam), &aiparam);
256nodata: 256nodata:
257 if (addrs.v) 257 kfree(addrs.v);
258 kfree(addrs.v);
259 return retval; 258 return retval;
260} 259}
261 260
@@ -347,8 +346,7 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
347nomem_chunk: 346nomem_chunk:
348 kfree(cookie); 347 kfree(cookie);
349nomem_cookie: 348nomem_cookie:
350 if (addrs.v) 349 kfree(addrs.v);
351 kfree(addrs.v);
352 return retval; 350 return retval;
353} 351}
354 352
diff --git a/net/sunrpc/auth_gss/gss_krb5_seal.c b/net/sunrpc/auth_gss/gss_krb5_seal.c
index 13f8ae979454..d0dfdfd5e79e 100644
--- a/net/sunrpc/auth_gss/gss_krb5_seal.c
+++ b/net/sunrpc/auth_gss/gss_krb5_seal.c
@@ -143,6 +143,6 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
143 143
144 return ((ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE); 144 return ((ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE);
145out_err: 145out_err:
146 if (md5cksum.data) kfree(md5cksum.data); 146 kfree(md5cksum.data);
147 return GSS_S_FAILURE; 147 return GSS_S_FAILURE;
148} 148}
diff --git a/net/sunrpc/auth_gss/gss_krb5_unseal.c b/net/sunrpc/auth_gss/gss_krb5_unseal.c
index 2030475d98ed..db055fd7d778 100644
--- a/net/sunrpc/auth_gss/gss_krb5_unseal.c
+++ b/net/sunrpc/auth_gss/gss_krb5_unseal.c
@@ -176,6 +176,6 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
176 176
177 ret = GSS_S_COMPLETE; 177 ret = GSS_S_COMPLETE;
178out: 178out:
179 if (md5cksum.data) kfree(md5cksum.data); 179 kfree(md5cksum.data);
180 return ret; 180 return ret;
181} 181}
diff --git a/net/sunrpc/auth_gss/gss_mech_switch.c b/net/sunrpc/auth_gss/gss_mech_switch.c
index b048bf672da2..f8bac6ccd524 100644
--- a/net/sunrpc/auth_gss/gss_mech_switch.c
+++ b/net/sunrpc/auth_gss/gss_mech_switch.c
@@ -60,8 +60,7 @@ gss_mech_free(struct gss_api_mech *gm)
60 60
61 for (i = 0; i < gm->gm_pf_num; i++) { 61 for (i = 0; i < gm->gm_pf_num; i++) {
62 pf = &gm->gm_pfs[i]; 62 pf = &gm->gm_pfs[i];
63 if (pf->auth_domain_name) 63 kfree(pf->auth_domain_name);
64 kfree(pf->auth_domain_name);
65 pf->auth_domain_name = NULL; 64 pf->auth_domain_name = NULL;
66 } 65 }
67} 66}
diff --git a/net/sunrpc/auth_gss/gss_spkm3_seal.c b/net/sunrpc/auth_gss/gss_spkm3_seal.c
index 148201e929d0..d1e12b25d6e2 100644
--- a/net/sunrpc/auth_gss/gss_spkm3_seal.c
+++ b/net/sunrpc/auth_gss/gss_spkm3_seal.c
@@ -122,8 +122,7 @@ spkm3_make_token(struct spkm3_ctx *ctx,
122 122
123 return GSS_S_COMPLETE; 123 return GSS_S_COMPLETE;
124out_err: 124out_err:
125 if (md5cksum.data) 125 kfree(md5cksum.data);
126 kfree(md5cksum.data);
127 token->data = NULL; 126 token->data = NULL;
128 token->len = 0; 127 token->len = 0;
129 return GSS_S_FAILURE; 128 return GSS_S_FAILURE;
diff --git a/net/sunrpc/auth_gss/gss_spkm3_token.c b/net/sunrpc/auth_gss/gss_spkm3_token.c
index 46c08a0710f6..1f824578d773 100644
--- a/net/sunrpc/auth_gss/gss_spkm3_token.c
+++ b/net/sunrpc/auth_gss/gss_spkm3_token.c
@@ -259,8 +259,7 @@ spkm3_verify_mic_token(unsigned char **tokp, int *mic_hdrlen, unsigned char **ck
259 259
260 ret = GSS_S_COMPLETE; 260 ret = GSS_S_COMPLETE;
261out: 261out:
262 if (spkm3_ctx_id.data) 262 kfree(spkm3_ctx_id.data);
263 kfree(spkm3_ctx_id.data);
264 return ret; 263 return ret;
265} 264}
266 265
diff --git a/net/sunrpc/auth_gss/gss_spkm3_unseal.c b/net/sunrpc/auth_gss/gss_spkm3_unseal.c
index c3c0d9586103..241d5b30dfcb 100644
--- a/net/sunrpc/auth_gss/gss_spkm3_unseal.c
+++ b/net/sunrpc/auth_gss/gss_spkm3_unseal.c
@@ -120,9 +120,7 @@ spkm3_read_token(struct spkm3_ctx *ctx,
120 /* XXX: need to add expiration and sequencing */ 120 /* XXX: need to add expiration and sequencing */
121 ret = GSS_S_COMPLETE; 121 ret = GSS_S_COMPLETE;
122out: 122out:
123 if (md5cksum.data) 123 kfree(md5cksum.data);
124 kfree(md5cksum.data); 124 kfree(wire_cksum.data);
125 if (wire_cksum.data)
126 kfree(wire_cksum.data);
127 return ret; 125 return ret;
128} 126}
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 4f188d0a5d11..81e00a6c19de 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -603,7 +603,7 @@ rpc_lookup_negative(char *path, struct nameidata *nd)
603 return ERR_PTR(error); 603 return ERR_PTR(error);
604 dir = nd->dentry->d_inode; 604 dir = nd->dentry->d_inode;
605 down(&dir->i_sem); 605 down(&dir->i_sem);
606 dentry = lookup_hash(&nd->last, nd->dentry); 606 dentry = lookup_hash(nd);
607 if (IS_ERR(dentry)) 607 if (IS_ERR(dentry))
608 goto out_err; 608 goto out_err;
609 if (dentry->d_inode) { 609 if (dentry->d_inode) {
@@ -665,7 +665,7 @@ rpc_rmdir(char *path)
665 return error; 665 return error;
666 dir = nd.dentry->d_inode; 666 dir = nd.dentry->d_inode;
667 down(&dir->i_sem); 667 down(&dir->i_sem);
668 dentry = lookup_hash(&nd.last, nd.dentry); 668 dentry = lookup_hash(&nd);
669 if (IS_ERR(dentry)) { 669 if (IS_ERR(dentry)) {
670 error = PTR_ERR(dentry); 670 error = PTR_ERR(dentry);
671 goto out_release; 671 goto out_release;
@@ -726,7 +726,7 @@ rpc_unlink(char *path)
726 return error; 726 return error;
727 dir = nd.dentry->d_inode; 727 dir = nd.dentry->d_inode;
728 down(&dir->i_sem); 728 down(&dir->i_sem);
729 dentry = lookup_hash(&nd.last, nd.dentry); 729 dentry = lookup_hash(&nd);
730 if (IS_ERR(dentry)) { 730 if (IS_ERR(dentry)) {
731 error = PTR_ERR(dentry); 731 error = PTR_ERR(dentry);
732 goto out_release; 732 goto out_release;
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 5a220b2bb376..e4296c8b861e 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -196,12 +196,9 @@ svc_exit_thread(struct svc_rqst *rqstp)
196 struct svc_serv *serv = rqstp->rq_server; 196 struct svc_serv *serv = rqstp->rq_server;
197 197
198 svc_release_buffer(rqstp); 198 svc_release_buffer(rqstp);
199 if (rqstp->rq_resp) 199 kfree(rqstp->rq_resp);
200 kfree(rqstp->rq_resp); 200 kfree(rqstp->rq_argp);
201 if (rqstp->rq_argp) 201 kfree(rqstp->rq_auth_data);
202 kfree(rqstp->rq_argp);
203 if (rqstp->rq_auth_data)
204 kfree(rqstp->rq_auth_data);
205 kfree(rqstp); 202 kfree(rqstp);
206 203
207 /* Release the server */ 204 /* Release the server */
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 32df43372ee9..aaf08cdd19f0 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -992,8 +992,7 @@ xdr_xcode_array2(struct xdr_buf *buf, unsigned int base,
992 err = 0; 992 err = 0;
993 993
994out: 994out:
995 if (elem) 995 kfree(elem);
996 kfree(elem);
997 if (ppages) 996 if (ppages)
998 kunmap(*ppages); 997 kunmap(*ppages);
999 return err; 998 return err;
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 41feca3bef86..acc73ba8bade 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -676,7 +676,7 @@ static struct sock *unix_find_other(struct sockaddr_un *sunname, int len,
676 err = path_lookup(sunname->sun_path, LOOKUP_FOLLOW, &nd); 676 err = path_lookup(sunname->sun_path, LOOKUP_FOLLOW, &nd);
677 if (err) 677 if (err)
678 goto fail; 678 goto fail;
679 err = permission(nd.dentry->d_inode,MAY_WRITE, &nd); 679 err = vfs_permission(&nd, MAY_WRITE);
680 if (err) 680 if (err)
681 goto put_fail; 681 goto put_fail;
682 682
diff --git a/net/wanrouter/af_wanpipe.c b/net/wanrouter/af_wanpipe.c
index 596cb96e5f47..59fec59b2132 100644
--- a/net/wanrouter/af_wanpipe.c
+++ b/net/wanrouter/af_wanpipe.c
@@ -1099,7 +1099,7 @@ static void release_driver(struct sock *sk)
1099 sock_reset_flag(sk, SOCK_ZAPPED); 1099 sock_reset_flag(sk, SOCK_ZAPPED);
1100 wp = wp_sk(sk); 1100 wp = wp_sk(sk);
1101 1101
1102 if (wp && wp->mbox) { 1102 if (wp) {
1103 kfree(wp->mbox); 1103 kfree(wp->mbox);
1104 wp->mbox = NULL; 1104 wp->mbox = NULL;
1105 } 1105 }
@@ -1186,10 +1186,8 @@ static void wanpipe_kill_sock_timer (unsigned long data)
1186 return; 1186 return;
1187 } 1187 }
1188 1188
1189 if (wp_sk(sk)) { 1189 kfree(wp_sk(sk));
1190 kfree(wp_sk(sk)); 1190 wp_sk(sk) = NULL;
1191 wp_sk(sk) = NULL;
1192 }
1193 1191
1194 if (atomic_read(&sk->sk_refcnt) != 1) { 1192 if (atomic_read(&sk->sk_refcnt) != 1) {
1195 atomic_set(&sk->sk_refcnt, 1); 1193 atomic_set(&sk->sk_refcnt, 1);
@@ -1219,10 +1217,8 @@ static void wanpipe_kill_sock_accept (struct sock *sk)
1219 sk->sk_socket = NULL; 1217 sk->sk_socket = NULL;
1220 1218
1221 1219
1222 if (wp_sk(sk)) { 1220 kfree(wp_sk(sk));
1223 kfree(wp_sk(sk)); 1221 wp_sk(sk) = NULL;
1224 wp_sk(sk) = NULL;
1225 }
1226 1222
1227 if (atomic_read(&sk->sk_refcnt) != 1) { 1223 if (atomic_read(&sk->sk_refcnt) != 1) {
1228 atomic_set(&sk->sk_refcnt, 1); 1224 atomic_set(&sk->sk_refcnt, 1);
@@ -1243,10 +1239,8 @@ static void wanpipe_kill_sock_irq (struct sock *sk)
1243 1239
1244 sk->sk_socket = NULL; 1240 sk->sk_socket = NULL;
1245 1241
1246 if (wp_sk(sk)) { 1242 kfree(wp_sk(sk));
1247 kfree(wp_sk(sk)); 1243 wp_sk(sk) = NULL;
1248 wp_sk(sk) = NULL;
1249 }
1250 1244
1251 if (atomic_read(&sk->sk_refcnt) != 1) { 1245 if (atomic_read(&sk->sk_refcnt) != 1) {
1252 atomic_set(&sk->sk_refcnt, 1); 1246 atomic_set(&sk->sk_refcnt, 1);
diff --git a/net/wanrouter/wanmain.c b/net/wanrouter/wanmain.c
index 13b650ad22e2..bcf7b3faa76a 100644
--- a/net/wanrouter/wanmain.c
+++ b/net/wanrouter/wanmain.c
@@ -714,10 +714,8 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
714 } 714 }
715 715
716 /* This code has moved from del_if() function */ 716 /* This code has moved from del_if() function */
717 if (dev->priv) { 717 kfree(dev->priv);
718 kfree(dev->priv); 718 dev->priv = NULL;
719 dev->priv = NULL;
720 }
721 719
722#ifdef CONFIG_WANPIPE_MULTPPP 720#ifdef CONFIG_WANPIPE_MULTPPP
723 if (cnf->config_id == WANCONFIG_MPPP) 721 if (cnf->config_id == WANCONFIG_MPPP)
@@ -851,10 +849,8 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
851 849
852 /* Due to new interface linking method using dev->priv, 850 /* Due to new interface linking method using dev->priv,
853 * this code has moved from del_if() function.*/ 851 * this code has moved from del_if() function.*/
854 if (dev->priv){ 852 kfree(dev->priv);
855 kfree(dev->priv); 853 dev->priv=NULL;
856 dev->priv=NULL;
857 }
858 854
859 unregister_netdev(dev); 855 unregister_netdev(dev);
860 856
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 8b9a4747417d..7cf48aa6c95b 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -62,14 +62,10 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x)
62{ 62{
63 if (del_timer(&x->timer)) 63 if (del_timer(&x->timer))
64 BUG(); 64 BUG();
65 if (x->aalg) 65 kfree(x->aalg);
66 kfree(x->aalg); 66 kfree(x->ealg);
67 if (x->ealg) 67 kfree(x->calg);
68 kfree(x->ealg); 68 kfree(x->encap);
69 if (x->calg)
70 kfree(x->calg);
71 if (x->encap)
72 kfree(x->encap);
73 if (x->type) { 69 if (x->type) {
74 x->type->destructor(x); 70 x->type->destructor(x);
75 xfrm_put_type(x->type); 71 xfrm_put_type(x->type);