caif: Remove unused enum and parameter in cfserl
[linux-2.6.git] / net / caif / caif_socket.c
index 653db75..a986280 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/uaccess.h>
 #include <linux/debugfs.h>
 #include <linux/caif/caif_socket.h>
-#include <asm/atomic.h>
+#include <linux/atomic.h>
 #include <net/sock.h>
 #include <net/tcp_states.h>
 #include <net/caif/caif_layer.h>
@@ -48,6 +48,7 @@ static struct dentry *debugfsdir;
 #ifdef CONFIG_DEBUG_FS
 struct debug_fs_counter {
        atomic_t caif_nr_socks;
+       atomic_t caif_sock_create;
        atomic_t num_connect_req;
        atomic_t num_connect_resp;
        atomic_t num_connect_fail_resp;
@@ -59,11 +60,11 @@ struct debug_fs_counter {
        atomic_t num_rx_flow_on;
 };
 static struct debug_fs_counter cnt;
-#define        dbfs_atomic_inc(v) atomic_inc(v)
-#define        dbfs_atomic_dec(v) atomic_dec(v)
+#define        dbfs_atomic_inc(v) atomic_inc_return(v)
+#define        dbfs_atomic_dec(v) atomic_dec_return(v)
 #else
-#define        dbfs_atomic_inc(v)
-#define        dbfs_atomic_dec(v)
+#define        dbfs_atomic_inc(v) 0
+#define        dbfs_atomic_dec(v) 0
 #endif
 
 struct caifsock {
@@ -155,9 +156,10 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
        if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
                (unsigned)sk->sk_rcvbuf && rx_flow_is_on(cf_sk)) {
-               pr_debug("sending flow OFF (queue len = %d %d)\n",
-                       atomic_read(&cf_sk->sk.sk_rmem_alloc),
-                       sk_rcvbuf_lowwater(cf_sk));
+               if (net_ratelimit())
+                       pr_debug("sending flow OFF (queue len = %d %d)\n",
+                                       atomic_read(&cf_sk->sk.sk_rmem_alloc),
+                                       sk_rcvbuf_lowwater(cf_sk));
                set_rx_flow_off(cf_sk);
                dbfs_atomic_inc(&cnt.num_rx_flow_off);
                caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
@@ -168,7 +170,8 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
                return err;
        if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
                set_rx_flow_off(cf_sk);
-               pr_debug("sending flow OFF due to rmem_schedule\n");
+               if (net_ratelimit())
+                       pr_debug("sending flow OFF due to rmem_schedule\n");
                dbfs_atomic_inc(&cnt.num_rx_flow_off);
                caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
        }
@@ -202,7 +205,7 @@ static int caif_sktrecv_cb(struct cflayer *layr, struct cfpkt *pkt)
        skb = cfpkt_tonative(pkt);
 
        if (unlikely(cf_sk->sk.sk_state != CAIF_CONNECTED)) {
-               cfpkt_destroy(pkt);
+               kfree_skb(skb);
                return 0;
        }
        caif_queue_rcv_skb(&cf_sk->sk, skb);
@@ -534,7 +537,7 @@ static int transmit_skb(struct sk_buff *skb, struct caifsock *cf_sk,
        struct cfpkt *pkt;
 
        pkt = cfpkt_fromnative(CAIF_DIR_OUT, skb);
-       memset(cfpkt_info(pkt), 0, sizeof(struct caif_payload_info));
+       memset(skb->cb, 0, sizeof(struct caif_payload_info));
 
        if (cf_sk->layer.dn == NULL)
                return -EINVAL;
@@ -604,7 +607,9 @@ static int caif_seqpkt_sendmsg(struct kiocb *kiocb, struct socket *sock,
                goto err;
        ret = transmit_skb(skb, cf_sk, noblock, timeo);
        if (ret < 0)
-               goto err;
+               /* skb is already freed */
+               return ret;
+
        return len;
 err:
        kfree_skb(skb);
@@ -811,6 +816,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
                if (sk->sk_shutdown & SHUTDOWN_MASK) {
                        /* Allow re-connect after SHUTDOWN_IND */
                        caif_disconnect_client(sock_net(sk), &cf_sk->layer);
+                       caif_free_client(&cf_sk->layer);
                        break;
                }
                /* No reconnect on a seqpacket socket */
@@ -836,7 +842,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
        sock->state = SS_CONNECTING;
        sk->sk_state = CAIF_CONNECTING;
 
-       /* Check priority value coming from socket */
+       /* Check priority value comming from socket */
        /* if priority value is out of range it will be ajusted */
        if (cf_sk->sk.sk_priority > CAIF_PRIO_MAX)
                cf_sk->conn_req.priority = CAIF_PRIO_MAX;
@@ -921,7 +927,6 @@ static int caif_release(struct socket *sock)
 {
        struct sock *sk = sock->sk;
        struct caifsock *cf_sk = container_of(sk, struct caifsock, sk);
-       int res = 0;
 
        if (!sk)
                return 0;
@@ -933,13 +938,14 @@ static int caif_release(struct socket *sock)
         * caif_queue_rcv_skb checks SOCK_DEAD holding the queue lock,
         * this ensures no packets when sock is dead.
         */
-       spin_lock(&sk->sk_receive_queue.lock);
+       spin_lock_bh(&sk->sk_receive_queue.lock);
        sock_set_flag(sk, SOCK_DEAD);
-       spin_unlock(&sk->sk_receive_queue.lock);
+       spin_unlock_bh(&sk->sk_receive_queue.lock);
        sock->sk = NULL;
 
        dbfs_atomic_inc(&cnt.num_disconnect);
 
+       WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
        if (cf_sk->debugfs_socket_dir != NULL)
                debugfs_remove_recursive(cf_sk->debugfs_socket_dir);
 
@@ -947,10 +953,7 @@ static int caif_release(struct socket *sock)
        sk->sk_state = CAIF_DISCONNECTED;
        sk->sk_shutdown = SHUTDOWN_MASK;
 
-       if (cf_sk->sk.sk_socket->state == SS_CONNECTED ||
-               cf_sk->sk.sk_socket->state == SS_CONNECTING)
-               res = caif_disconnect_client(sock_net(sk), &cf_sk->layer);
-
+       caif_disconnect_client(sock_net(sk), &cf_sk->layer);
        cf_sk->sk.sk_socket->state = SS_DISCONNECTING;
        wake_up_interruptible_poll(sk_sleep(sk), POLLERR|POLLHUP);
 
@@ -958,7 +961,7 @@ static int caif_release(struct socket *sock)
        sk_stream_kill_queues(&cf_sk->sk);
        release_sock(sk);
        sock_put(sk);
-       return res;
+       return 0;
 }
 
 /* Copied from af_unix.c:unix_poll(), added CAIF tx_flow handling */
@@ -1045,7 +1048,7 @@ static void caif_sock_destructor(struct sock *sk)
        caif_assert(sk_unhashed(sk));
        caif_assert(!sk->sk_socket);
        if (!sock_flag(sk, SOCK_DEAD)) {
-               pr_info("Attempt to release alive CAIF socket: %p\n", sk);
+               pr_debug("Attempt to release alive CAIF socket: %p\n", sk);
                return;
        }
        sk_stream_kill_queues(&cf_sk->sk);
@@ -1056,6 +1059,7 @@ static void caif_sock_destructor(struct sock *sk)
 static int caif_create(struct net *net, struct socket *sock, int protocol,
                        int kern)
 {
+       int num;
        struct sock *sk = NULL;
        struct caifsock *cf_sk = NULL;
        static struct proto prot = {.name = "PF_CAIF",
@@ -1113,19 +1117,21 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
        set_rx_flow_on(cf_sk);
 
        /* Set default options on configuration */
-       cf_sk->sk.sk_priority= CAIF_PRIO_NORMAL;
+       cf_sk->sk.sk_priority = CAIF_PRIO_NORMAL;
        cf_sk->conn_req.link_selector = CAIF_LINK_LOW_LATENCY;
        cf_sk->conn_req.protocol = protocol;
        /* Increase the number of sockets created. */
        dbfs_atomic_inc(&cnt.caif_nr_socks);
+       num = dbfs_atomic_inc(&cnt.caif_sock_create);
 #ifdef CONFIG_DEBUG_FS
        if (!IS_ERR(debugfsdir)) {
+
                /* Fill in some information concerning the misc socket. */
-               snprintf(cf_sk->name, sizeof(cf_sk->name), "cfsk%d",
-                               atomic_read(&cnt.caif_nr_socks));
+               snprintf(cf_sk->name, sizeof(cf_sk->name), "cfsk%d", num);
 
                cf_sk->debugfs_socket_dir =
                        debugfs_create_dir(cf_sk->name, debugfsdir);
+
                debugfs_create_u32("sk_state", S_IRUSR | S_IWUSR,
                                cf_sk->debugfs_socket_dir,
                                (u32 *) &cf_sk->sk.sk_state);
@@ -1169,6 +1175,9 @@ static int __init caif_sktinit_module(void)
                debugfs_create_u32("num_sockets", S_IRUSR | S_IWUSR,
                                debugfsdir,
                                (u32 *) &cnt.caif_nr_socks);
+               debugfs_create_u32("num_create", S_IRUSR | S_IWUSR,
+                               debugfsdir,
+                               (u32 *) &cnt.caif_sock_create);
                debugfs_create_u32("num_connect_req", S_IRUSR | S_IWUSR,
                                debugfsdir,
                                (u32 *) &cnt.num_connect_req);