* [AX.25 1/7] Mark all kmalloc users __must_check
@ 2006-12-14 22:42 Ralf Baechle
2006-12-14 22:42 ` [AX.25 2/7] Fix unchecked ax25_protocol_register uses Ralf Baechle
` (6 more replies)
0 siblings, 7 replies; 14+ messages in thread
From: Ralf Baechle @ 2006-12-14 22:42 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-hams, Ralf Baechle
The recent fix 0506d4068bad834aab1141b5dc5e748eb175c6b3 made obvious that
error values were not being propagated through the AX.25 stack. To help
with that this patch marks all kmalloc users in the AX.25, NETROM and
ROSE stacks as __must_check.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
include/net/ax25.h | 11 ++++++-----
include/net/rose.h | 4 ++--
net/ax25/af_ax25.c | 4 ++--
net/ax25/ax25_route.c | 2 +-
net/netrom/nr_route.c | 8 +++++---
net/rose/rose_route.c | 2 +-
6 files changed, 17 insertions(+), 14 deletions(-)
Index: linux-net/include/net/ax25.h
===================================================================
--- linux-net.orig/include/net/ax25.h
+++ linux-net/include/net/ax25.h
@@ -277,7 +277,7 @@ struct sock *ax25_get_socket(ax25_addres
extern ax25_cb *ax25_find_cb(ax25_address *, ax25_address *, ax25_digi *, struct net_device *);
extern void ax25_send_to_raw(ax25_address *, struct sk_buff *, int);
extern void ax25_destroy_socket(ax25_cb *);
-extern ax25_cb *ax25_create_cb(void);
+extern ax25_cb * __must_check ax25_create_cb(void);
extern void ax25_fillin_cb(ax25_cb *, ax25_dev *);
extern struct sock *ax25_make_new(struct sock *, struct ax25_dev *);
@@ -333,11 +333,12 @@ extern void ax25_ds_t3timer_expiry(ax25_
extern void ax25_ds_idletimer_expiry(ax25_cb *);
/* ax25_iface.c */
-extern int ax25_protocol_register(unsigned int, int (*)(struct sk_buff *, ax25_cb *));
+extern int __must_check ax25_protocol_register(unsigned int, int (*)(struct sk_buff *, ax25_cb *));
extern void ax25_protocol_release(unsigned int);
-extern int ax25_linkfail_register(void (*)(ax25_cb *, int));
+extern int __must_check ax25_linkfail_register(void (*)(ax25_cb *, int));
extern void ax25_linkfail_release(void (*)(ax25_cb *, int));
-extern int ax25_listen_register(ax25_address *, struct net_device *);
+extern int __must_check ax25_listen_register(ax25_address *,
+ struct net_device *);
extern void ax25_listen_release(ax25_address *, struct net_device *);
extern int (*ax25_protocol_function(unsigned int))(struct sk_buff *, ax25_cb *);
extern int ax25_listen_mine(ax25_address *, struct net_device *);
@@ -415,7 +416,7 @@ extern unsigned long ax25_display_timer(
/* ax25_uid.c */
extern int ax25_uid_policy;
extern ax25_uid_assoc *ax25_findbyuid(uid_t);
-extern int ax25_uid_ioctl(int, struct sockaddr_ax25 *);
+extern int __must_check ax25_uid_ioctl(int, struct sockaddr_ax25 *);
extern struct file_operations ax25_uid_fops;
extern void ax25_uid_free(void);
Index: linux-net/include/net/rose.h
===================================================================
--- linux-net.orig/include/net/rose.h
+++ linux-net/include/net/rose.h
@@ -193,8 +193,8 @@ extern struct file_operations rose_neigh
extern struct file_operations rose_nodes_fops;
extern struct file_operations rose_routes_fops;
-extern int rose_add_loopback_neigh(void);
-extern int rose_add_loopback_node(rose_address *);
+extern int __must_check rose_add_loopback_neigh(void);
+extern int __must_check rose_add_loopback_node(rose_address *);
extern void rose_del_loopback_node(rose_address *);
extern void rose_rt_device_down(struct net_device *);
extern void rose_link_device_down(struct net_device *);
Index: linux-net/net/ax25/af_ax25.c
===================================================================
--- linux-net.orig/net/ax25/af_ax25.c
+++ linux-net/net/ax25/af_ax25.c
@@ -1088,8 +1088,8 @@ out:
/*
* FIXME: nonblock behaviour looks like it may have a bug.
*/
-static int ax25_connect(struct socket *sock, struct sockaddr *uaddr,
- int addr_len, int flags)
+static int __must_check ax25_connect(struct socket *sock,
+ struct sockaddr *uaddr, int addr_len, int flags)
{
struct sock *sk = sock->sk;
ax25_cb *ax25 = ax25_sk(sk), *ax25t;
Index: linux-net/net/ax25/ax25_route.c
===================================================================
--- linux-net.orig/net/ax25/ax25_route.c
+++ linux-net/net/ax25/ax25_route.c
@@ -71,7 +71,7 @@ void ax25_rt_device_down(struct net_devi
write_unlock(&ax25_route_lock);
}
-static int ax25_rt_add(struct ax25_routes_struct *route)
+static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
{
ax25_route *ax25_rt;
ax25_dev *ax25_dev;
Index: linux-net/net/rose/rose_route.c
===================================================================
--- linux-net.orig/net/rose/rose_route.c
+++ linux-net/net/rose/rose_route.c
@@ -52,7 +52,7 @@ struct rose_neigh *rose_loopback_neigh;
* Add a new route to a node, and in the process add the node and the
* neighbour if it is new.
*/
-static int rose_add_node(struct rose_route_struct *rose_route,
+static int __must_check rose_add_node(struct rose_route_struct *rose_route,
struct net_device *dev)
{
struct rose_node *rose_node, *rose_tmpn, *rose_tmpp;
Index: linux-net/net/netrom/nr_route.c
===================================================================
--- linux-net.orig/net/netrom/nr_route.c
+++ linux-net/net/netrom/nr_route.c
@@ -87,8 +87,9 @@ static void nr_remove_neigh(struct nr_ne
* Add a new route to a node, and in the process add the node and the
* neighbour if it is new.
*/
-static int nr_add_node(ax25_address *nr, const char *mnemonic, ax25_address *ax25,
- ax25_digi *ax25_digi, struct net_device *dev, int quality, int obs_count)
+static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
+ ax25_address *ax25, ax25_digi *ax25_digi, struct net_device *dev,
+ int quality, int obs_count)
{
struct nr_node *nr_node;
struct nr_neigh *nr_neigh;
@@ -406,7 +407,8 @@ static int nr_del_node(ax25_address *cal
/*
* Lock a neighbour with a quality.
*/
-static int nr_add_neigh(ax25_address *callsign, ax25_digi *ax25_digi, struct net_device *dev, unsigned int quality)
+static int __must_check nr_add_neigh(ax25_address *callsign,
+ ax25_digi *ax25_digi, struct net_device *dev, unsigned int quality)
{
struct nr_neigh *nr_neigh;
^ permalink raw reply [flat|nested] 14+ messages in thread
* [AX.25 2/7] Fix unchecked ax25_protocol_register uses.
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
@ 2006-12-14 22:42 ` Ralf Baechle
2006-12-14 23:52 ` David Miller
2006-12-14 22:42 ` [AX.25 3/7] Fix unchecked ax25_listen_register uses Ralf Baechle
` (5 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Ralf Baechle @ 2006-12-14 22:42 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-hams, Ralf Baechle
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>
include/net/ax25.h | 9 ++++++++-
net/ax25/ax25_iface.c | 41 ++++++++++++-----------------------------
net/netrom/af_netrom.c | 7 ++++++-
net/rose/af_rose.c | 7 ++++++-
4 files changed, 32 insertions(+), 32 deletions(-)
Index: linux-net/include/net/ax25.h
===================================================================
--- linux-net.orig/include/net/ax25.h
+++ linux-net/include/net/ax25.h
@@ -333,7 +333,14 @@ extern void ax25_ds_t3timer_expiry(ax25_
extern void ax25_ds_idletimer_expiry(ax25_cb *);
/* ax25_iface.c */
-extern int __must_check ax25_protocol_register(unsigned int, int (*)(struct sk_buff *, ax25_cb *));
+
+struct ax25_protocol {
+ struct ax25_protocol *next;
+ unsigned int pid;
+ int (*func)(struct sk_buff *, ax25_cb *);
+};
+
+extern void ax25_register_pid(struct ax25_protocol *ap);
extern void ax25_protocol_release(unsigned int);
extern int __must_check ax25_linkfail_register(void (*)(ax25_cb *, int));
extern void ax25_linkfail_release(void (*)(ax25_cb *, int));
Index: linux-net/net/ax25/ax25_iface.c
===================================================================
--- linux-net.orig/net/ax25/ax25_iface.c
+++ linux-net/net/ax25/ax25_iface.c
@@ -29,11 +29,7 @@
#include <linux/mm.h>
#include <linux/interrupt.h>
-static struct protocol_struct {
- struct protocol_struct *next;
- unsigned int pid;
- int (*func)(struct sk_buff *, ax25_cb *);
-} *protocol_list = NULL;
+static struct ax25_protocol *protocol_list;
static DEFINE_RWLOCK(protocol_list_lock);
static struct linkfail_struct {
@@ -49,36 +45,23 @@ static struct listen_struct {
} *listen_list = NULL;
static DEFINE_SPINLOCK(listen_lock);
-int ax25_protocol_register(unsigned int pid,
- int (*func)(struct sk_buff *, ax25_cb *))
+/*
+ * Do not register the internal protocols AX25_P_TEXT, AX25_P_SEGMENT,
+ * AX25_P_IP or AX25_P_ARP ...
+ */
+void ax25_register_pid(struct ax25_protocol *ap)
{
- struct protocol_struct *protocol;
-
- if (pid == AX25_P_TEXT || pid == AX25_P_SEGMENT)
- return 0;
-#ifdef CONFIG_INET
- if (pid == AX25_P_IP || pid == AX25_P_ARP)
- return 0;
-#endif
- if ((protocol = kmalloc(sizeof(*protocol), GFP_ATOMIC)) == NULL)
- return 0;
-
- protocol->pid = pid;
- protocol->func = func;
-
write_lock_bh(&protocol_list_lock);
- protocol->next = protocol_list;
- protocol_list = protocol;
+ ap->next = protocol_list;
+ protocol_list = ap;
write_unlock_bh(&protocol_list_lock);
-
- return 1;
}
-EXPORT_SYMBOL(ax25_protocol_register);
+EXPORT_SYMBOL_GPL(ax25_register_pid);
void ax25_protocol_release(unsigned int pid)
{
- struct protocol_struct *s, *protocol;
+ struct ax25_protocol *s, *protocol;
write_lock_bh(&protocol_list_lock);
protocol = protocol_list;
@@ -223,7 +206,7 @@ EXPORT_SYMBOL(ax25_listen_release);
int (*ax25_protocol_function(unsigned int pid))(struct sk_buff *, ax25_cb *)
{
int (*res)(struct sk_buff *, ax25_cb *) = NULL;
- struct protocol_struct *protocol;
+ struct ax25_protocol *protocol;
read_lock(&protocol_list_lock);
for (protocol = protocol_list; protocol != NULL; protocol = protocol->next)
@@ -263,7 +246,7 @@ void ax25_link_failed(ax25_cb *ax25, int
int ax25_protocol_is_registered(unsigned int pid)
{
- struct protocol_struct *protocol;
+ struct ax25_protocol *protocol;
int res = 0;
read_lock_bh(&protocol_list_lock);
Index: linux-net/net/netrom/af_netrom.c
===================================================================
--- linux-net.orig/net/netrom/af_netrom.c
+++ linux-net/net/netrom/af_netrom.c
@@ -1377,6 +1377,11 @@ static struct notifier_block nr_dev_noti
static struct net_device **dev_nr;
+static struct ax25_protocol nr_pid = {
+ .pid = AX25_P_NETROM,
+ .func = nr_route_frame
+};
+
static int __init nr_proto_init(void)
{
int i;
@@ -1424,7 +1429,7 @@ static int __init nr_proto_init(void)
register_netdevice_notifier(&nr_dev_notifier);
- ax25_protocol_register(AX25_P_NETROM, nr_route_frame);
+ ax25_register_pid(&nr_pid);
ax25_linkfail_register(nr_link_failed);
#ifdef CONFIG_SYSCTL
Index: linux-net/net/rose/af_rose.c
===================================================================
--- linux-net.orig/net/rose/af_rose.c
+++ linux-net/net/rose/af_rose.c
@@ -1481,6 +1481,11 @@ static struct notifier_block rose_dev_no
static struct net_device **dev_rose;
+static struct ax25_protocol rose_pid = {
+ .pid = AX25_P_ROSE,
+ .func = rose_route_frame
+};
+
static int __init rose_proto_init(void)
{
int i;
@@ -1530,7 +1535,7 @@ static int __init rose_proto_init(void)
sock_register(&rose_family_ops);
register_netdevice_notifier(&rose_dev_notifier);
- ax25_protocol_register(AX25_P_ROSE, rose_route_frame);
+ ax25_register_pid(&rose_pid);
ax25_linkfail_register(rose_link_failed);
#ifdef CONFIG_SYSCTL
^ permalink raw reply [flat|nested] 14+ messages in thread
* [AX.25 3/7] Fix unchecked ax25_listen_register uses
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
2006-12-14 22:42 ` [AX.25 2/7] Fix unchecked ax25_protocol_register uses Ralf Baechle
@ 2006-12-14 22:42 ` Ralf Baechle
2006-12-14 23:52 ` David Miller
2006-12-14 22:42 ` [AX.25 4/7] Fix unchecked nr_add_node uses Ralf Baechle
` (4 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Ralf Baechle @ 2006-12-14 22:42 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-hams, Ralf Baechle
Fix ax25_listen_register to return something that's a sane error code,
then all callers to use it.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
net/ax25/ax25_iface.c | 7 ++++---
net/netrom/nr_dev.c | 24 ++++++++++++++++++------
net/rose/af_rose.c | 3 ++-
3 files changed, 24 insertions(+), 10 deletions(-)
Index: linux-net/net/ax25/ax25_iface.c
===================================================================
--- linux-net.orig/net/ax25/ax25_iface.c
+++ linux-net/net/ax25/ax25_iface.c
@@ -154,7 +154,7 @@ int ax25_listen_register(ax25_address *c
return 0;
if ((listen = kmalloc(sizeof(*listen), GFP_ATOMIC)) == NULL)
- return 0;
+ return -ENOMEM;
listen->callsign = *callsign;
listen->dev = dev;
@@ -164,7 +164,7 @@ int ax25_listen_register(ax25_address *c
listen_list = listen;
spin_unlock_bh(&listen_lock);
- return 1;
+ return 0;
}
EXPORT_SYMBOL(ax25_listen_register);
@@ -225,7 +225,8 @@ int ax25_listen_mine(ax25_address *calls
spin_lock_bh(&listen_lock);
for (listen = listen_list; listen != NULL; listen = listen->next)
- if (ax25cmp(&listen->callsign, callsign) == 0 && (listen->dev == dev || listen->dev == NULL)) {
+ if (ax25cmp(&listen->callsign, callsign) == 0 &&
+ (listen->dev == dev || listen->dev == NULL)) {
spin_unlock_bh(&listen_lock);
return 1;
}
Index: linux-net/net/netrom/nr_dev.c
===================================================================
--- linux-net.orig/net/netrom/nr_dev.c
+++ linux-net/net/netrom/nr_dev.c
@@ -128,25 +128,37 @@ static int nr_header(struct sk_buff *skb
return -37;
}
-static int nr_set_mac_address(struct net_device *dev, void *addr)
+static int __must_check nr_set_mac_address(struct net_device *dev, void *addr)
{
struct sockaddr *sa = addr;
+ int err;
+
+ if (!memcmp(dev->dev_addr, sa->sa_data, dev->addr_len))
+ return 0;
+
+ if (dev->flags & IFF_UP) {
+ err = ax25_listen_register((ax25_address *)sa->sa_data, NULL);
+ if (err)
+ return err;
- if (dev->flags & IFF_UP)
ax25_listen_release((ax25_address *)dev->dev_addr, NULL);
+ }
memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
- if (dev->flags & IFF_UP)
- ax25_listen_register((ax25_address *)dev->dev_addr, NULL);
-
return 0;
}
static int nr_open(struct net_device *dev)
{
+ int err;
+
+ err = ax25_listen_register((ax25_address *)dev->dev_addr, NULL);
+ if (err)
+ return err;
+
netif_start_queue(dev);
- ax25_listen_register((ax25_address *)dev->dev_addr, NULL);
+
return 0;
}
Index: linux-net/net/rose/af_rose.c
===================================================================
--- linux-net.orig/net/rose/af_rose.c
+++ linux-net/net/rose/af_rose.c
@@ -1314,7 +1314,8 @@ static int rose_ioctl(struct socket *soc
if (copy_from_user(&rose_callsign, argp, sizeof(ax25_address)))
return -EFAULT;
if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
- ax25_listen_register(&rose_callsign, NULL);
+ return ax25_listen_register(&rose_callsign, NULL);
+
return 0;
case SIOCRSGL2CALL:
^ permalink raw reply [flat|nested] 14+ messages in thread
* [AX.25 4/7] Fix unchecked nr_add_node uses
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
2006-12-14 22:42 ` [AX.25 2/7] Fix unchecked ax25_protocol_register uses Ralf Baechle
2006-12-14 22:42 ` [AX.25 3/7] Fix unchecked ax25_listen_register uses Ralf Baechle
@ 2006-12-14 22:42 ` Ralf Baechle
2006-12-14 23:52 ` David Miller
2006-12-14 22:42 ` [AX.25 5/7] Fix unchecked ax25_linkfail_register uses Ralf Baechle
` (3 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Ralf Baechle @ 2006-12-14 22:42 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-hams, Ralf Baechle
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
net/netrom/nr_route.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
Index: linux-net/net/netrom/nr_route.c
===================================================================
--- linux-net.orig/net/netrom/nr_route.c
+++ linux-net/net/netrom/nr_route.c
@@ -779,9 +779,13 @@ int nr_route_frame(struct sk_buff *skb,
nr_src = (ax25_address *)(skb->data + 0);
nr_dest = (ax25_address *)(skb->data + 7);
- if (ax25 != NULL)
- nr_add_node(nr_src, "", &ax25->dest_addr, ax25->digipeat,
- ax25->ax25_dev->dev, 0, sysctl_netrom_obsolescence_count_initialiser);
+ if (ax25 != NULL) {
+ ret = nr_add_node(nr_src, "", &ax25->dest_addr, ax25->digipeat,
+ ax25->ax25_dev->dev, 0,
+ sysctl_netrom_obsolescence_count_initialiser);
+ if (ret)
+ return ret;
+ }
if ((dev = nr_dev_get(nr_dest)) != NULL) { /* Its for me */
if (ax25 == NULL) /* Its from me */
@@ -846,6 +850,7 @@ int nr_route_frame(struct sk_buff *skb,
ret = (nr_neigh->ax25 != NULL);
nr_node_unlock(nr_node);
nr_node_put(nr_node);
+
return ret;
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [AX.25 5/7] Fix unchecked ax25_linkfail_register uses
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
` (2 preceding siblings ...)
2006-12-14 22:42 ` [AX.25 4/7] Fix unchecked nr_add_node uses Ralf Baechle
@ 2006-12-14 22:42 ` Ralf Baechle
2006-12-14 23:53 ` David Miller
2006-12-14 22:42 ` [AX.25 6/7] Fix unchecked rose_add_loopback_node uses Ralf Baechle
` (2 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Ralf Baechle @ 2006-12-14 22:42 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-hams, Ralf Baechle
ax25_linkfail_register uses kmalloc and the callers were ignoring the
error value. Rewrite to let the caller deal with the allocation. This
allows the use of static allocation of kmalloc use entirely.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
include/net/ax25.h | 10 +++++++-
net/ax25/ax25_iface.c | 55 ++++++++-----------------------------------------
net/netrom/af_netrom.c | 8 +++++--
net/rose/af_rose.c | 8 +++++--
4 files changed, 29 insertions(+), 52 deletions(-)
Index: linux-net/include/net/ax25.h
===================================================================
--- linux-net.orig/include/net/ax25.h
+++ linux-net/include/net/ax25.h
@@ -342,8 +342,14 @@ struct ax25_protocol {
extern void ax25_register_pid(struct ax25_protocol *ap);
extern void ax25_protocol_release(unsigned int);
-extern int __must_check ax25_linkfail_register(void (*)(ax25_cb *, int));
-extern void ax25_linkfail_release(void (*)(ax25_cb *, int));
+
+struct ax25_linkfail {
+ struct hlist_node lf_node;
+ void (*func)(ax25_cb *, int);
+};
+
+extern void ax25_linkfail_register(struct ax25_linkfail *lf);
+extern void ax25_linkfail_release(struct ax25_linkfail *lf);
extern int __must_check ax25_listen_register(ax25_address *,
struct net_device *);
extern void ax25_listen_release(ax25_address *, struct net_device *);
Index: linux-net/net/ax25/ax25_iface.c
===================================================================
--- linux-net.orig/net/ax25/ax25_iface.c
+++ linux-net/net/ax25/ax25_iface.c
@@ -32,10 +32,7 @@
static struct ax25_protocol *protocol_list;
static DEFINE_RWLOCK(protocol_list_lock);
-static struct linkfail_struct {
- struct linkfail_struct *next;
- void (*func)(ax25_cb *, int);
-} *linkfail_list = NULL;
+static HLIST_HEAD(ax25_linkfail_list);
static DEFINE_SPINLOCK(linkfail_lock);
static struct listen_struct {
@@ -93,54 +90,19 @@ void ax25_protocol_release(unsigned int
EXPORT_SYMBOL(ax25_protocol_release);
-int ax25_linkfail_register(void (*func)(ax25_cb *, int))
+void ax25_linkfail_register(struct ax25_linkfail *lf)
{
- struct linkfail_struct *linkfail;
-
- if ((linkfail = kmalloc(sizeof(*linkfail), GFP_ATOMIC)) == NULL)
- return 0;
-
- linkfail->func = func;
-
spin_lock_bh(&linkfail_lock);
- linkfail->next = linkfail_list;
- linkfail_list = linkfail;
+ hlist_add_head(&lf->lf_node, &ax25_linkfail_list);
spin_unlock_bh(&linkfail_lock);
-
- return 1;
}
EXPORT_SYMBOL(ax25_linkfail_register);
-void ax25_linkfail_release(void (*func)(ax25_cb *, int))
+void ax25_linkfail_release(struct ax25_linkfail *lf)
{
- struct linkfail_struct *s, *linkfail;
-
spin_lock_bh(&linkfail_lock);
- linkfail = linkfail_list;
- if (linkfail == NULL) {
- spin_unlock_bh(&linkfail_lock);
- return;
- }
-
- if (linkfail->func == func) {
- linkfail_list = linkfail->next;
- spin_unlock_bh(&linkfail_lock);
- kfree(linkfail);
- return;
- }
-
- while (linkfail != NULL && linkfail->next != NULL) {
- if (linkfail->next->func == func) {
- s = linkfail->next;
- linkfail->next = linkfail->next->next;
- spin_unlock_bh(&linkfail_lock);
- kfree(s);
- return;
- }
-
- linkfail = linkfail->next;
- }
+ hlist_del_init(&lf->lf_node);
spin_unlock_bh(&linkfail_lock);
}
@@ -237,11 +199,12 @@ int (*ax25_protocol_function(unsigned in
void ax25_link_failed(ax25_cb *ax25, int reason)
{
- struct linkfail_struct *linkfail;
+ struct ax25_linkfail *lf;
+ struct hlist_node *node;
spin_lock_bh(&linkfail_lock);
- for (linkfail = linkfail_list; linkfail != NULL; linkfail = linkfail->next)
- (linkfail->func)(ax25, reason);
+ hlist_for_each_entry(lf, node, &ax25_linkfail_list, lf_node)
+ lf->func(ax25, reason);
spin_unlock_bh(&linkfail_lock);
}
Index: linux-net/net/netrom/af_netrom.c
===================================================================
--- linux-net.orig/net/netrom/af_netrom.c
+++ linux-net/net/netrom/af_netrom.c
@@ -1382,6 +1382,10 @@ static struct ax25_protocol nr_pid = {
.func = nr_route_frame
};
+static struct ax25_linkfail nr_linkfail_notifier = {
+ .func = nr_link_failed,
+};
+
static int __init nr_proto_init(void)
{
int i;
@@ -1430,7 +1434,7 @@ static int __init nr_proto_init(void)
register_netdevice_notifier(&nr_dev_notifier);
ax25_register_pid(&nr_pid);
- ax25_linkfail_register(nr_link_failed);
+ ax25_linkfail_register(&nr_linkfail_notifier);
#ifdef CONFIG_SYSCTL
nr_register_sysctl();
@@ -1479,7 +1483,7 @@ static void __exit nr_exit(void)
nr_unregister_sysctl();
#endif
- ax25_linkfail_release(nr_link_failed);
+ ax25_linkfail_release(&nr_linkfail_notifier);
ax25_protocol_release(AX25_P_NETROM);
unregister_netdevice_notifier(&nr_dev_notifier);
Index: linux-net/net/rose/af_rose.c
===================================================================
--- linux-net.orig/net/rose/af_rose.c
+++ linux-net/net/rose/af_rose.c
@@ -1487,6 +1487,10 @@ static struct ax25_protocol rose_pid = {
.func = rose_route_frame
};
+static struct ax25_linkfail rose_linkfail_notifier = {
+ .func = rose_link_failed
+};
+
static int __init rose_proto_init(void)
{
int i;
@@ -1537,7 +1541,7 @@ static int __init rose_proto_init(void)
register_netdevice_notifier(&rose_dev_notifier);
ax25_register_pid(&rose_pid);
- ax25_linkfail_register(rose_link_failed);
+ ax25_linkfail_register(&rose_linkfail_notifier);
#ifdef CONFIG_SYSCTL
rose_register_sysctl();
@@ -1585,7 +1589,7 @@ static void __exit rose_exit(void)
rose_rt_free();
ax25_protocol_release(AX25_P_ROSE);
- ax25_linkfail_release(rose_link_failed);
+ ax25_linkfail_release(&rose_linkfail_notifier);
if (ax25cmp(&rose_callsign, &null_ax25_address) != 0)
ax25_listen_release(&rose_callsign, NULL);
^ permalink raw reply [flat|nested] 14+ messages in thread
* [AX.25 6/7] Fix unchecked rose_add_loopback_node uses
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
` (3 preceding siblings ...)
2006-12-14 22:42 ` [AX.25 5/7] Fix unchecked ax25_linkfail_register uses Ralf Baechle
@ 2006-12-14 22:42 ` Ralf Baechle
2006-12-14 23:53 ` David Miller
2006-12-14 22:42 ` [AX.25 7/7] Fix unchecked rose_add_loopback_neigh uses Ralf Baechle
2006-12-14 23:52 ` [AX.25 1/7] Mark all kmalloc users __must_check David Miller
6 siblings, 1 reply; 14+ messages in thread
From: Ralf Baechle @ 2006-12-14 22:42 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-hams, Ralf Baechle
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
net/rose/rose_dev.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
Index: linux-net/net/rose/rose_dev.c
===================================================================
--- linux-net.orig/net/rose/rose_dev.c
+++ linux-net/net/rose/rose_dev.c
@@ -93,20 +93,34 @@ static int rose_rebuild_header(struct sk
static int rose_set_mac_address(struct net_device *dev, void *addr)
{
struct sockaddr *sa = addr;
+ int err;
- rose_del_loopback_node((rose_address *)dev->dev_addr);
+ if (!memcpy(dev->dev_addr, sa->sa_data, dev->addr_len))
+ return 0;
- memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
+ if (dev->flags & IFF_UP) {
+ err = rose_add_loopback_node((rose_address *)dev->dev_addr);
+ if (err)
+ return err;
+
+ rose_del_loopback_node((rose_address *)dev->dev_addr);
+ }
- rose_add_loopback_node((rose_address *)dev->dev_addr);
+ memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
return 0;
}
static int rose_open(struct net_device *dev)
{
+ int err;
+
+ err = rose_add_loopback_node((rose_address *)dev->dev_addr);
+ if (err)
+ return err;
+
netif_start_queue(dev);
- rose_add_loopback_node((rose_address *)dev->dev_addr);
+
return 0;
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [AX.25 7/7] Fix unchecked rose_add_loopback_neigh uses
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
` (4 preceding siblings ...)
2006-12-14 22:42 ` [AX.25 6/7] Fix unchecked rose_add_loopback_node uses Ralf Baechle
@ 2006-12-14 22:42 ` Ralf Baechle
2006-12-14 23:53 ` David Miller
2006-12-14 23:52 ` [AX.25 1/7] Mark all kmalloc users __must_check David Miller
6 siblings, 1 reply; 14+ messages in thread
From: Ralf Baechle @ 2006-12-14 22:42 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-hams, Ralf Baechle
rose_add_loopback_neigh uses kmalloc and the callers were ignoring the
error value. Rewrite to let the caller deal with the allocation. This
allows the use of static allocation of kmalloc use entirely.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
include/net/rose.h | 4 ++--
net/rose/rose_loopback.c | 5 +++--
net/rose/rose_route.c | 45 +++++++++++++++++++++------------------------
3 files changed, 26 insertions(+), 28 deletions(-)
Index: linux-net/include/net/rose.h
===================================================================
--- linux-net.orig/include/net/rose.h
+++ linux-net/include/net/rose.h
@@ -188,12 +188,12 @@ extern void rose_kick(struct sock *);
extern void rose_enquiry_response(struct sock *);
/* rose_route.c */
-extern struct rose_neigh *rose_loopback_neigh;
+extern struct rose_neigh rose_loopback_neigh;
extern struct file_operations rose_neigh_fops;
extern struct file_operations rose_nodes_fops;
extern struct file_operations rose_routes_fops;
-extern int __must_check rose_add_loopback_neigh(void);
+extern void rose_add_loopback_neigh(void);
extern int __must_check rose_add_loopback_node(rose_address *);
extern void rose_del_loopback_node(rose_address *);
extern void rose_rt_device_down(struct net_device *);
Index: linux-net/net/rose/rose_loopback.c
===================================================================
--- linux-net.orig/net/rose/rose_loopback.c
+++ linux-net/net/rose/rose_loopback.c
@@ -79,7 +79,8 @@ static void rose_loopback_timer(unsigned
skb->h.raw = skb->data;
- if ((sk = rose_find_socket(lci_o, rose_loopback_neigh)) != NULL) {
+ sk = rose_find_socket(lci_o, &rose_loopback_neigh);
+ if (sk) {
if (rose_process_rx_frame(sk, skb) == 0)
kfree_skb(skb);
continue;
@@ -87,7 +88,7 @@ static void rose_loopback_timer(unsigned
if (frametype == ROSE_CALL_REQUEST) {
if ((dev = rose_dev_get(dest)) != NULL) {
- if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0)
+ if (rose_rx_call_request(skb, dev, &rose_loopback_neigh, lci_o) == 0)
kfree_skb(skb);
} else {
kfree_skb(skb);
Index: linux-net/net/rose/rose_route.c
===================================================================
--- linux-net.orig/net/rose/rose_route.c
+++ linux-net/net/rose/rose_route.c
@@ -46,7 +46,7 @@ static DEFINE_SPINLOCK(rose_neigh_list_l
static struct rose_route *rose_route_list;
static DEFINE_SPINLOCK(rose_route_list_lock);
-struct rose_neigh *rose_loopback_neigh;
+struct rose_neigh rose_loopback_neigh;
/*
* Add a new route to a node, and in the process add the node and the
@@ -361,33 +361,30 @@ out:
/*
* Add the loopback neighbour.
*/
-int rose_add_loopback_neigh(void)
+void rose_add_loopback_neigh(void)
{
- if ((rose_loopback_neigh = kmalloc(sizeof(struct rose_neigh), GFP_ATOMIC)) == NULL)
- return -ENOMEM;
+ struct rose_neigh *sn = &rose_loopback_neigh;
- rose_loopback_neigh->callsign = null_ax25_address;
- rose_loopback_neigh->digipeat = NULL;
- rose_loopback_neigh->ax25 = NULL;
- rose_loopback_neigh->dev = NULL;
- rose_loopback_neigh->count = 0;
- rose_loopback_neigh->use = 0;
- rose_loopback_neigh->dce_mode = 1;
- rose_loopback_neigh->loopback = 1;
- rose_loopback_neigh->number = rose_neigh_no++;
- rose_loopback_neigh->restarted = 1;
+ sn->callsign = null_ax25_address;
+ sn->digipeat = NULL;
+ sn->ax25 = NULL;
+ sn->dev = NULL;
+ sn->count = 0;
+ sn->use = 0;
+ sn->dce_mode = 1;
+ sn->loopback = 1;
+ sn->number = rose_neigh_no++;
+ sn->restarted = 1;
- skb_queue_head_init(&rose_loopback_neigh->queue);
+ skb_queue_head_init(&sn->queue);
- init_timer(&rose_loopback_neigh->ftimer);
- init_timer(&rose_loopback_neigh->t0timer);
+ init_timer(&sn->ftimer);
+ init_timer(&sn->t0timer);
spin_lock_bh(&rose_neigh_list_lock);
- rose_loopback_neigh->next = rose_neigh_list;
- rose_neigh_list = rose_loopback_neigh;
+ sn->next = rose_neigh_list;
+ rose_neigh_list = sn;
spin_unlock_bh(&rose_neigh_list_lock);
-
- return 0;
}
/*
@@ -421,13 +418,13 @@ int rose_add_loopback_node(rose_address
rose_node->mask = 10;
rose_node->count = 1;
rose_node->loopback = 1;
- rose_node->neighbour[0] = rose_loopback_neigh;
+ rose_node->neighbour[0] = &rose_loopback_neigh;
/* Insert at the head of list. Address is always mask=10 */
rose_node->next = rose_node_list;
rose_node_list = rose_node;
- rose_loopback_neigh->count++;
+ rose_loopback_neigh.count++;
out:
spin_unlock_bh(&rose_node_list_lock);
@@ -458,7 +455,7 @@ void rose_del_loopback_node(rose_address
rose_remove_node(rose_node);
- rose_loopback_neigh->count--;
+ rose_loopback_neigh.count--;
out:
spin_unlock_bh(&rose_node_list_lock);
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [AX.25 1/7] Mark all kmalloc users __must_check
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
` (5 preceding siblings ...)
2006-12-14 22:42 ` [AX.25 7/7] Fix unchecked rose_add_loopback_neigh uses Ralf Baechle
@ 2006-12-14 23:52 ` David Miller
6 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2006-12-14 23:52 UTC (permalink / raw)
To: ralf; +Cc: netdev, linux-hams
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 14 Dec 2006 23:42:07 +0100
> The recent fix 0506d4068bad834aab1141b5dc5e748eb175c6b3 made obvious that
> error values were not being propagated through the AX.25 stack. To help
> with that this patch marks all kmalloc users in the AX.25, NETROM and
> ROSE stacks as __must_check.
>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [AX.25 2/7] Fix unchecked ax25_protocol_register uses.
2006-12-14 22:42 ` [AX.25 2/7] Fix unchecked ax25_protocol_register uses Ralf Baechle
@ 2006-12-14 23:52 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2006-12-14 23:52 UTC (permalink / raw)
To: ralf; +Cc: netdev, linux-hams
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 14 Dec 2006 23:42:08 +0100
> 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>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [AX.25 3/7] Fix unchecked ax25_listen_register uses
2006-12-14 22:42 ` [AX.25 3/7] Fix unchecked ax25_listen_register uses Ralf Baechle
@ 2006-12-14 23:52 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2006-12-14 23:52 UTC (permalink / raw)
To: ralf; +Cc: netdev, linux-hams
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 14 Dec 2006 23:42:09 +0100
> Fix ax25_listen_register to return something that's a sane error code,
> then all callers to use it.
>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [AX.25 4/7] Fix unchecked nr_add_node uses
2006-12-14 22:42 ` [AX.25 4/7] Fix unchecked nr_add_node uses Ralf Baechle
@ 2006-12-14 23:52 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2006-12-14 23:52 UTC (permalink / raw)
To: ralf; +Cc: netdev, linux-hams
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 14 Dec 2006 23:42:10 +0100
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [AX.25 5/7] Fix unchecked ax25_linkfail_register uses
2006-12-14 22:42 ` [AX.25 5/7] Fix unchecked ax25_linkfail_register uses Ralf Baechle
@ 2006-12-14 23:53 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2006-12-14 23:53 UTC (permalink / raw)
To: ralf; +Cc: netdev, linux-hams
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 14 Dec 2006 23:42:11 +0100
> ax25_linkfail_register uses kmalloc and the callers were ignoring the
> error value. Rewrite to let the caller deal with the allocation. This
> allows the use of static allocation of kmalloc use entirely.
>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [AX.25 6/7] Fix unchecked rose_add_loopback_node uses
2006-12-14 22:42 ` [AX.25 6/7] Fix unchecked rose_add_loopback_node uses Ralf Baechle
@ 2006-12-14 23:53 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2006-12-14 23:53 UTC (permalink / raw)
To: ralf; +Cc: netdev, linux-hams
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 14 Dec 2006 23:42:12 +0100
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [AX.25 7/7] Fix unchecked rose_add_loopback_neigh uses
2006-12-14 22:42 ` [AX.25 7/7] Fix unchecked rose_add_loopback_neigh uses Ralf Baechle
@ 2006-12-14 23:53 ` David Miller
0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2006-12-14 23:53 UTC (permalink / raw)
To: ralf; +Cc: netdev, linux-hams
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 14 Dec 2006 23:42:13 +0100
> rose_add_loopback_neigh uses kmalloc and the callers were ignoring the
> error value. Rewrite to let the caller deal with the allocation. This
> allows the use of static allocation of kmalloc use entirely.
>
> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Applied.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2006-12-15 0:12 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-14 22:42 [AX.25 1/7] Mark all kmalloc users __must_check Ralf Baechle
2006-12-14 22:42 ` [AX.25 2/7] Fix unchecked ax25_protocol_register uses Ralf Baechle
2006-12-14 23:52 ` David Miller
2006-12-14 22:42 ` [AX.25 3/7] Fix unchecked ax25_listen_register uses Ralf Baechle
2006-12-14 23:52 ` David Miller
2006-12-14 22:42 ` [AX.25 4/7] Fix unchecked nr_add_node uses Ralf Baechle
2006-12-14 23:52 ` David Miller
2006-12-14 22:42 ` [AX.25 5/7] Fix unchecked ax25_linkfail_register uses Ralf Baechle
2006-12-14 23:53 ` David Miller
2006-12-14 22:42 ` [AX.25 6/7] Fix unchecked rose_add_loopback_node uses Ralf Baechle
2006-12-14 23:53 ` David Miller
2006-12-14 22:42 ` [AX.25 7/7] Fix unchecked rose_add_loopback_neigh uses Ralf Baechle
2006-12-14 23:53 ` David Miller
2006-12-14 23:52 ` [AX.25 1/7] Mark all kmalloc users __must_check David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).