Merge branch 'topic/core-cleanup' into for-linus
[safe/jmp/linux-2.6] / net / sctp / socket.c
index 71513b3..44a1ab0 100644 (file)
@@ -67,6 +67,7 @@
 #include <linux/poll.h>
 #include <linux/init.h>
 #include <linux/crypto.h>
+#include <linux/slab.h>
 
 #include <net/ip.h>
 #include <net/icmp.h>
@@ -2087,8 +2088,7 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval,
        if (copy_from_user(&sp->autoclose, optval, optlen))
                return -EFAULT;
        /* make sure it won't exceed MAX_SCHEDULE_TIMEOUT */
-       if (sp->autoclose > (MAX_SCHEDULE_TIMEOUT / HZ) )
-               sp->autoclose = MAX_SCHEDULE_TIMEOUT / HZ ;
+       sp->autoclose = min_t(long, sp->autoclose, MAX_SCHEDULE_TIMEOUT / HZ);
 
        return 0;
 }
@@ -2356,8 +2356,8 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
            pmtud_change     == SPP_PMTUD ||
            sackdelay_change == SPP_SACKDELAY ||
            params.spp_sackdelay > 500 ||
-           (params.spp_pathmtu
-           && params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
+           (params.spp_pathmtu &&
+            params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
                return -EINVAL;
 
        /* If an address other than INADDR_ANY is specified, and
@@ -3719,9 +3719,12 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
        sp->hmac = NULL;
 
        SCTP_DBG_OBJCNT_INC(sock);
-       percpu_counter_inc(&sctp_sockets_allocated);
+
+       /* Set socket backlog limit. */
+       sk->sk_backlog.limit = sysctl_sctp_rmem[1];
 
        local_bh_disable();
+       percpu_counter_inc(&sctp_sockets_allocated);
        sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
        local_bh_enable();
 
@@ -3738,8 +3741,8 @@ SCTP_STATIC void sctp_destroy_sock(struct sock *sk)
        /* Release our hold on the endpoint. */
        ep = sctp_sk(sk)->ep;
        sctp_endpoint_free(ep);
-       percpu_counter_dec(&sctp_sockets_allocated);
        local_bh_disable();
+       percpu_counter_dec(&sctp_sockets_allocated);
        sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
        local_bh_enable();
 }
@@ -6186,6 +6189,16 @@ do_nonblock:
        goto out;
 }
 
+void sctp_data_ready(struct sock *sk, int len)
+{
+       read_lock_bh(&sk->sk_callback_lock);
+       if (sk_has_sleeper(sk))
+               wake_up_interruptible_sync_poll(sk->sk_sleep, POLLIN |
+                                               POLLRDNORM | POLLRDBAND);
+       sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
+       read_unlock_bh(&sk->sk_callback_lock);
+}
+
 /* If socket sndbuf has changed, wake up all per association waiters.  */
 void sctp_write_space(struct sock *sk)
 {
@@ -6360,7 +6373,7 @@ void sctp_copy_sock(struct sock *newsk, struct sock *sk,
                    struct sctp_association *asoc)
 {
        struct inet_sock *inet = inet_sk(sk);
-       struct inet_sock *newinet = inet_sk(newsk);
+       struct inet_sock *newinet;
 
        newsk->sk_type = sk->sk_type;
        newsk->sk_bound_dev_if = sk->sk_bound_dev_if;