include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / net / ax25 / af_ax25.c
index 01c83e2..65c5801 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/string.h>
 #include <linux/sockios.h>
 #include <linux/net.h>
+#include <linux/slab.h>
 #include <net/ax25.h>
 #include <linux/inet.h>
 #include <linux/netdevice.h>
@@ -317,6 +318,9 @@ void ax25_destroy_socket(ax25_cb *ax25)
                                /* Queue the unaccepted socket for death */
                                sock_orphan(skb->sk);
 
+                               /* 9A4GL: hack to release unaccepted sockets */
+                               skb->sk->sk_state = TCP_LISTEN;
+
                                ax25_start_heartbeat(sax25);
                                sax25->state = AX25_STATE_0;
                        }
@@ -327,8 +331,7 @@ void ax25_destroy_socket(ax25_cb *ax25)
        }
 
        if (ax25->sk != NULL) {
-               if (atomic_read(&ax25->sk->sk_wmem_alloc) ||
-                   atomic_read(&ax25->sk->sk_rmem_alloc)) {
+               if (sk_has_allocations(ax25->sk)) {
                        /* Defer: outstanding buffers */
                        setup_timer(&ax25->dtimer, ax25_destroy_timer,
                                        (unsigned long)ax25);
@@ -356,6 +359,7 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
        ax25_dev *ax25_dev;
        ax25_cb *ax25;
        unsigned int k;
+       int ret = 0;
 
        if (copy_from_user(&ax25_ctl, arg, sizeof(ax25_ctl)))
                return -EFAULT;
@@ -366,6 +370,9 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
        if (ax25_ctl.digi_count > AX25_MAX_DIGIS)
                return -EINVAL;
 
+       if (ax25_ctl.arg > ULONG_MAX / HZ && ax25_ctl.cmd != AX25_KILL)
+               return -EINVAL;
+
        digi.ndigi = ax25_ctl.digi_count;
        for (k = 0; k < digi.ndigi; k++)
                digi.calls[k] = ax25_ctl.digi_addr[k];
@@ -386,57 +393,59 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
        case AX25_WINDOW:
                if (ax25->modulus == AX25_MODULUS) {
                        if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7)
-                               return -EINVAL;
+                               goto einval_put;
                } else {
                        if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63)
-                               return -EINVAL;
+                               goto einval_put;
                }
                ax25->window = ax25_ctl.arg;
                break;
 
        case AX25_T1:
                if (ax25_ctl.arg < 1)
-                       return -EINVAL;
+                       goto einval_put;
                ax25->rtt = (ax25_ctl.arg * HZ) / 2;
                ax25->t1  = ax25_ctl.arg * HZ;
                break;
 
        case AX25_T2:
                if (ax25_ctl.arg < 1)
-                       return -EINVAL;
+                       goto einval_put;
                ax25->t2 = ax25_ctl.arg * HZ;
                break;
 
        case AX25_N2:
                if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31)
-                       return -EINVAL;
+                       goto einval_put;
                ax25->n2count = 0;
                ax25->n2 = ax25_ctl.arg;
                break;
 
        case AX25_T3:
-               if (ax25_ctl.arg < 0)
-                       return -EINVAL;
                ax25->t3 = ax25_ctl.arg * HZ;
                break;
 
        case AX25_IDLE:
-               if (ax25_ctl.arg < 0)
-                       return -EINVAL;
                ax25->idle = ax25_ctl.arg * 60 * HZ;
                break;
 
        case AX25_PACLEN:
                if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535)
-                       return -EINVAL;
+                       goto einval_put;
                ax25->paclen = ax25_ctl.arg;
                break;
 
        default:
-               return -EINVAL;
+               goto einval_put;
          }
 
-       return 0;
+out_put:
+       ax25_cb_put(ax25);
+       return ret;
+
+einval_put:
+       ret = -EINVAL;
+       goto out_put;
 }
 
 static void ax25_fillin_cb_from_dev(ax25_cb *ax25, ax25_dev *ax25_dev)
@@ -525,7 +534,7 @@ ax25_cb *ax25_create_cb(void)
  */
 
 static int ax25_setsockopt(struct socket *sock, int level, int optname,
-       char __user *optval, int optlen)
+       char __user *optval, unsigned int optlen)
 {
        struct sock *sk = sock->sk;
        ax25_cb *ax25;
@@ -632,15 +641,10 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
 
        case SO_BINDTODEVICE:
                if (optlen > IFNAMSIZ)
-                       optlen=IFNAMSIZ;
-               if (copy_from_user(devname, optval, optlen)) {
-               res = -EFAULT;
-                       break;
-               }
+                       optlen = IFNAMSIZ;
 
-               dev = dev_get_by_name(&init_net, devname);
-               if (dev == NULL) {
-                       res = -ENODEV;
+               if (copy_from_user(devname, optval, optlen)) {
+                       res = -EFAULT;
                        break;
                }
 
@@ -648,12 +652,18 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
                   (sock->state != SS_UNCONNECTED ||
                    sk->sk_state == TCP_LISTEN)) {
                        res = -EADDRNOTAVAIL;
-                       dev_put(dev);
+                       break;
+               }
+
+               dev = dev_get_by_name(&init_net, devname);
+               if (!dev) {
+                       res = -ENODEV;
                        break;
                }
 
                ax25->ax25_dev = ax25_dev_ax25dev(dev);
                ax25_fillin_cb(ax25, ax25->ax25_dev);
+               dev_put(dev);
                break;
 
        default:
@@ -790,12 +800,13 @@ static struct proto ax25_proto = {
        .obj_size = sizeof(struct sock),
 };
 
-static int ax25_create(struct net *net, struct socket *sock, int protocol)
+static int ax25_create(struct net *net, struct socket *sock, int protocol,
+                      int kern)
 {
        struct sock *sk;
        ax25_cb *ax25;
 
-       if (net != &init_net)
+       if (!net_eq(net, &init_net))
                return -EAFNOSUPPORT;
 
        switch (sock->type) {
@@ -891,7 +902,6 @@ struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
 
        sock_init_data(NULL, sk);
 
-       sk->sk_destruct = ax25_free_sock;
        sk->sk_type     = osk->sk_type;
        sk->sk_priority = osk->sk_priority;
        sk->sk_protocol = osk->sk_protocol;
@@ -929,6 +939,7 @@ struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
        }
 
        sk->sk_protinfo = ax25;
+       sk->sk_destruct = ax25_free_sock;
        ax25->sk    = sk;
 
        return sk;
@@ -1042,7 +1053,7 @@ static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
        if (addr->fsa_ax25.sax25_family != AF_AX25)
                return -EINVAL;
 
-       user = ax25_findbyuid(current->euid);
+       user = ax25_findbyuid(current_euid());
        if (user) {
                call = user->call;
                ax25_uid_put(user);
@@ -1526,10 +1537,8 @@ static int ax25_sendmsg(struct kiocb *iocb, struct socket *sock,
                dp = ax25->digipeat;
        }
 
-       SOCK_DEBUG(sk, "AX.25: sendto: Addresses built.\n");
-
        /* Build a packet */
-       SOCK_DEBUG(sk, "AX.25: sendto: building packet.\n");
+       SOCK_DEBUG(sk, "AX.25: sendto: Addresses built. Building packet.\n");
 
        /* Assume the worst case */
        size = len + ax25->ax25_dev->dev->hard_header_len;
@@ -1690,7 +1699,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        switch (cmd) {
        case TIOCOUTQ: {
                long amount;
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                res = put_user(amount, (int __user *)argp);
@@ -1780,8 +1790,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                ax25_info.idletimer = ax25_display_timer(&ax25->idletimer) / (60 * HZ);
                ax25_info.n2count   = ax25->n2count;
                ax25_info.state     = ax25->state;
-               ax25_info.rcv_q     = atomic_read(&sk->sk_rmem_alloc);
-               ax25_info.snd_q     = atomic_read(&sk->sk_wmem_alloc);
+               ax25_info.rcv_q     = sk_rmem_alloc_get(sk);
+               ax25_info.snd_q     = sk_wmem_alloc_get(sk);
                ax25_info.vs        = ax25->vs;
                ax25_info.vr        = ax25->vr;
                ax25_info.va        = ax25->va;
@@ -1854,25 +1864,13 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 static void *ax25_info_start(struct seq_file *seq, loff_t *pos)
        __acquires(ax25_list_lock)
 {
-       struct ax25_cb *ax25;
-       struct hlist_node *node;
-       int i = 0;
-
        spin_lock_bh(&ax25_list_lock);
-       ax25_for_each(ax25, node, &ax25_list) {
-               if (i == *pos)
-                       return ax25;
-               ++i;
-       }
-       return NULL;
+       return seq_hlist_start(&ax25_list, *pos);
 }
 
 static void *ax25_info_next(struct seq_file *seq, void *v, loff_t *pos)
 {
-       ++*pos;
-
-       return hlist_entry( ((struct ax25_cb *)v)->ax25_node.next,
-                           struct ax25_cb, ax25_node);
+       return seq_hlist_next(v, &ax25_list, pos);
 }
 
 static void ax25_info_stop(struct seq_file *seq, void *v)
@@ -1883,7 +1881,7 @@ static void ax25_info_stop(struct seq_file *seq, void *v)
 
 static int ax25_info_show(struct seq_file *seq, void *v)
 {
-       ax25_cb *ax25 = v;
+       ax25_cb *ax25 = hlist_entry(v, struct ax25_cb, ax25_node);
        char buf[11];
        int k;
 
@@ -1921,8 +1919,8 @@ static int ax25_info_show(struct seq_file *seq, void *v)
 
        if (ax25->sk != NULL) {
                seq_printf(seq, " %d %d %lu\n",
-                          atomic_read(&ax25->sk->sk_wmem_alloc),
-                          atomic_read(&ax25->sk->sk_rmem_alloc),
+                          sk_wmem_alloc_get(ax25->sk),
+                          sk_rmem_alloc_get(ax25->sk),
                           sock_i_ino(ax25->sk));
        } else {
                seq_puts(seq, " * * *\n");
@@ -1952,7 +1950,7 @@ static const struct file_operations ax25_info_fops = {
 
 #endif
 
-static struct net_proto_family ax25_family_ops = {
+static const struct net_proto_family ax25_family_ops = {
        .family =       PF_AX25,
        .create =       ax25_create,
        .owner  =       THIS_MODULE,
@@ -1982,9 +1980,8 @@ static const struct proto_ops ax25_proto_ops = {
 /*
  *     Called by socket.c on kernel start up
  */
-static struct packet_type ax25_packet_type = {
-       .type   =       __constant_htons(ETH_P_AX25),
-       .dev    =       NULL,                           /* All devices */
+static struct packet_type ax25_packet_type __read_mostly = {
+       .type   =       cpu_to_be16(ETH_P_AX25),
        .func   =       ax25_kiss_rcv,
 };