Skip to content

Commit 8d5cf59

Browse files
ralfbaechleDavid S. Miller
authored andcommitted
[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>
1 parent c9266b9 commit 8d5cf59

4 files changed

Lines changed: 32 additions & 32 deletions

File tree

‎include/net/ax25.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,14 @@ extern void ax25_ds_t3timer_expiry(ax25_cb *);
333333
extern void ax25_ds_idletimer_expiry(ax25_cb *);
334334

335335
/* ax25_iface.c */
336-
extern int __must_check ax25_protocol_register(unsigned int, int (*)(struct sk_buff *, ax25_cb *));
336+
337+
struct ax25_protocol {
338+
struct ax25_protocol *next;
339+
unsigned int pid;
340+
int (*func)(struct sk_buff *, ax25_cb *);
341+
};
342+
343+
extern void ax25_register_pid(struct ax25_protocol *ap);
337344
extern void ax25_protocol_release(unsigned int);
338345
extern int __must_check ax25_linkfail_register(void (*)(ax25_cb *, int));
339346
extern void ax25_linkfail_release(void (*)(ax25_cb *, int));

‎net/ax25/ax25_iface.c‎

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
#include <linux/mm.h>
3030
#include <linux/interrupt.h>
3131

32-
static struct protocol_struct {
33-
struct protocol_struct *next;
34-
unsigned int pid;
35-
int (*func)(struct sk_buff *, ax25_cb *);
36-
} *protocol_list = NULL;
32+
static struct ax25_protocol *protocol_list;
3733
static DEFINE_RWLOCK(protocol_list_lock);
3834

3935
static struct linkfail_struct {
@@ -49,36 +45,23 @@ static struct listen_struct {
4945
} *listen_list = NULL;
5046
static DEFINE_SPINLOCK(listen_lock);
5147

52-
int ax25_protocol_register(unsigned int pid,
53-
int (*func)(struct sk_buff *, ax25_cb *))
48+
/*
49+
* Do not register the internal protocols AX25_P_TEXT, AX25_P_SEGMENT,
50+
* AX25_P_IP or AX25_P_ARP ...
51+
*/
52+
void ax25_register_pid(struct ax25_protocol *ap)
5453
{
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-
6954
write_lock_bh(&protocol_list_lock);
70-
protocol->next = protocol_list;
71-
protocol_list = protocol;
55+
ap->next = protocol_list;
56+
protocol_list = ap;
7257
write_unlock_bh(&protocol_list_lock);
73-
74-
return 1;
7558
}
7659

77-
EXPORT_SYMBOL(ax25_protocol_register);
60+
EXPORT_SYMBOL_GPL(ax25_register_pid);
7861

7962
void ax25_protocol_release(unsigned int pid)
8063
{
81-
struct protocol_struct *s, *protocol;
64+
struct ax25_protocol *s, *protocol;
8265

8366
write_lock_bh(&protocol_list_lock);
8467
protocol = protocol_list;
@@ -223,7 +206,7 @@ EXPORT_SYMBOL(ax25_listen_release);
223206
int (*ax25_protocol_function(unsigned int pid))(struct sk_buff *, ax25_cb *)
224207
{
225208
int (*res)(struct sk_buff *, ax25_cb *) = NULL;
226-
struct protocol_struct *protocol;
209+
struct ax25_protocol *protocol;
227210

228211
read_lock(&protocol_list_lock);
229212
for (protocol = protocol_list; protocol != NULL; protocol = protocol->next)
@@ -263,7 +246,7 @@ void ax25_link_failed(ax25_cb *ax25, int reason)
263246

264247
int ax25_protocol_is_registered(unsigned int pid)
265248
{
266-
struct protocol_struct *protocol;
249+
struct ax25_protocol *protocol;
267250
int res = 0;
268251

269252
read_lock_bh(&protocol_list_lock);

‎net/netrom/af_netrom.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,11 @@ static struct notifier_block nr_dev_notifier = {
13771377

13781378
static struct net_device **dev_nr;
13791379

1380+
static struct ax25_protocol nr_pid = {
1381+
.pid = AX25_P_NETROM,
1382+
.func = nr_route_frame
1383+
};
1384+
13801385
static int __init nr_proto_init(void)
13811386
{
13821387
int i;
@@ -1424,7 +1429,7 @@ static int __init nr_proto_init(void)
14241429

14251430
register_netdevice_notifier(&nr_dev_notifier);
14261431

1427-
ax25_protocol_register(AX25_P_NETROM, nr_route_frame);
1432+
ax25_register_pid(&nr_pid);
14281433
ax25_linkfail_register(nr_link_failed);
14291434

14301435
#ifdef CONFIG_SYSCTL

‎net/rose/af_rose.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,11 @@ static struct notifier_block rose_dev_notifier = {
14811481

14821482
static struct net_device **dev_rose;
14831483

1484+
static struct ax25_protocol rose_pid = {
1485+
.pid = AX25_P_ROSE,
1486+
.func = rose_route_frame
1487+
};
1488+
14841489
static int __init rose_proto_init(void)
14851490
{
14861491
int i;
@@ -1530,7 +1535,7 @@ static int __init rose_proto_init(void)
15301535
sock_register(&rose_family_ops);
15311536
register_netdevice_notifier(&rose_dev_notifier);
15321537

1533-
ax25_protocol_register(AX25_P_ROSE, rose_route_frame);
1538+
ax25_register_pid(&rose_pid);
15341539
ax25_linkfail_register(rose_link_failed);
15351540

15361541
#ifdef CONFIG_SYSCTL

0 commit comments

Comments
 (0)