aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2006-12-14 18:50:01 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-18 00:59:08 -0500
commit8d5cf596d10d740b69b5f4bbdb54b85abf75810d (patch)
treef0fd6a296f1b90d5fb1898ce1932c6ec5d245465 /net
parentc9266b99e2def0a456766220df09713f8e765891 (diff)
[AX.25]: Fix unchecked ax25_protocol_register uses.
Replace ax25_protocol_register by ax25_register_pid which assumes the caller has done the memory allocation. This allows replacing the kmalloc allocations entirely by static allocations. Signed-off-by: Ralf Baechle <ralf@linux-mips.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/ax25/ax25_iface.c41
-rw-r--r--net/netrom/af_netrom.c7
-rw-r--r--net/rose/af_rose.c7
3 files changed, 24 insertions, 31 deletions
diff --git a/net/ax25/ax25_iface.c b/net/ax25/ax25_iface.c
index 07ac0207eb69..dd9b7fee3df8 100644
--- a/net/ax25/ax25_iface.c
+++ b/net/ax25/ax25_iface.c
@@ -29,11 +29,7 @@
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31 31
32static struct protocol_struct { 32static struct ax25_protocol *protocol_list;
33 struct protocol_struct *next;
34 unsigned int pid;
35 int (*func)(struct sk_buff *, ax25_cb *);
36} *protocol_list = NULL;
37static DEFINE_RWLOCK(protocol_list_lock); 33static DEFINE_RWLOCK(protocol_list_lock);
38 34
39static struct linkfail_struct { 35static struct linkfail_struct {
@@ -49,36 +45,23 @@ static struct listen_struct {
49} *listen_list = NULL; 45} *listen_list = NULL;
50static DEFINE_SPINLOCK(listen_lock); 46static DEFINE_SPINLOCK(listen_lock);
51 47
52int ax25_protocol_register(unsigned int pid, 48/*
53 int (*func)(struct sk_buff *, ax25_cb *)) 49 * Do not register the internal protocols AX25_P_TEXT, AX25_P_SEGMENT,
50 * AX25_P_IP or AX25_P_ARP ...
51 */
52void ax25_register_pid(struct ax25_protocol *ap)
54{ 53{
55 struct protocol_struct *protocol;
56
57 if (pid == AX25_P_TEXT || pid == AX25_P_SEGMENT)
58 return 0;
59#ifdef CONFIG_INET
60 if (pid == AX25_P_IP || pid == AX25_P_ARP)
61 return 0;
62#endif
63 if ((protocol = kmalloc(sizeof(*protocol), GFP_ATOMIC)) == NULL)
64 return 0;
65
66 protocol->pid = pid;
67 protocol->func = func;
68
69 write_lock_bh(&protocol_list_lock); 54 write_lock_bh(&protocol_list_lock);
70 protocol->next = protocol_list; 55 ap->next = protocol_list;
71 protocol_list = protocol; 56 protocol_list = ap;
72 write_unlock_bh(&protocol_list_lock); 57 write_unlock_bh(&protocol_list_lock);
73
74 return 1;
75} 58}
76 59
77EXPORT_SYMBOL(ax25_protocol_register); 60EXPORT_SYMBOL_GPL(ax25_register_pid);
78 61
79void ax25_protocol_release(unsigned int pid) 62void ax25_protocol_release(unsigned int pid)
80{ 63{
81 struct protocol_struct *s, *protocol; 64 struct ax25_protocol *s, *protocol;
82 65
83 write_lock_bh(&protocol_list_lock); 66 write_lock_bh(&protocol_list_lock);
84 protocol = protocol_list; 67 protocol = protocol_list;
@@ -223,7 +206,7 @@ EXPORT_SYMBOL(ax25_listen_release);
223int (*ax25_protocol_function(unsigned int pid))(struct sk_buff *, ax25_cb *) 206int (*ax25_protocol_function(unsigned int pid))(struct sk_buff *, ax25_cb *)
224{ 207{
225 int (*res)(struct sk_buff *, ax25_cb *) = NULL; 208 int (*res)(struct sk_buff *, ax25_cb *) = NULL;
226 struct protocol_struct *protocol; 209 struct ax25_protocol *protocol;
227 210
228 read_lock(&protocol_list_lock); 211 read_lock(&protocol_list_lock);
229 for (protocol = protocol_list; protocol != NULL; protocol = protocol->next) 212 for (protocol = protocol_list; protocol != NULL; protocol = protocol->next)
@@ -263,7 +246,7 @@ void ax25_link_failed(ax25_cb *ax25, int reason)
263 246
264int ax25_protocol_is_registered(unsigned int pid) 247int ax25_protocol_is_registered(unsigned int pid)
265{ 248{
266 struct protocol_struct *protocol; 249 struct ax25_protocol *protocol;
267 int res = 0; 250 int res = 0;
268 251
269 read_lock_bh(&protocol_list_lock); 252 read_lock_bh(&protocol_list_lock);
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index 1d50f801f181..f4675bf3976c 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -1377,6 +1377,11 @@ static struct notifier_block nr_dev_notifier = {
1377 1377
1378static struct net_device **dev_nr; 1378static struct net_device **dev_nr;
1379 1379
1380static struct ax25_protocol nr_pid = {
1381 .pid = AX25_P_NETROM,
1382 .func = nr_route_frame
1383};
1384
1380static int __init nr_proto_init(void) 1385static int __init nr_proto_init(void)
1381{ 1386{
1382 int i; 1387 int i;
@@ -1424,7 +1429,7 @@ static int __init nr_proto_init(void)
1424 1429
1425 register_netdevice_notifier(&nr_dev_notifier); 1430 register_netdevice_notifier(&nr_dev_notifier);
1426 1431
1427 ax25_protocol_register(AX25_P_NETROM, nr_route_frame); 1432 ax25_register_pid(&nr_pid);
1428 ax25_linkfail_register(nr_link_failed); 1433 ax25_linkfail_register(nr_link_failed);
1429 1434
1430#ifdef CONFIG_SYSCTL 1435#ifdef CONFIG_SYSCTL
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index 08a542855654..1605069e5db1 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -1481,6 +1481,11 @@ static struct notifier_block rose_dev_notifier = {
1481 1481
1482static struct net_device **dev_rose; 1482static struct net_device **dev_rose;
1483 1483
1484static struct ax25_protocol rose_pid = {
1485 .pid = AX25_P_ROSE,
1486 .func = rose_route_frame
1487};
1488
1484static int __init rose_proto_init(void) 1489static int __init rose_proto_init(void)
1485{ 1490{
1486 int i; 1491 int i;
@@ -1530,7 +1535,7 @@ static int __init rose_proto_init(void)
1530 sock_register(&rose_family_ops); 1535 sock_register(&rose_family_ops);
1531 register_netdevice_notifier(&rose_dev_notifier); 1536 register_netdevice_notifier(&rose_dev_notifier);
1532 1537
1533 ax25_protocol_register(AX25_P_ROSE, rose_route_frame); 1538 ax25_register_pid(&rose_pid);
1534 ax25_linkfail_register(rose_link_failed); 1539 ax25_linkfail_register(rose_link_failed);
1535 1540
1536#ifdef CONFIG_SYSCTL 1541#ifdef CONFIG_SYSCTL