[PATCH v1 19/34] j1939: socket: add j1939_jsk_add/del functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



and start to use them

Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
---
 net/can/j1939/socket.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
index a94e36d54c2d..c78b41b55d21 100644
--- a/net/can/j1939/socket.c
+++ b/net/can/j1939/socket.c
@@ -69,6 +69,24 @@ void j1939_sock_pending_del(struct sock *sk)
 		wake_up(&jsk->waitq);	/* no pending SKB's */
 }
 
+static void j1939_jsk_add(struct j1939_priv *priv, struct j1939_sock *jsk)
+{
+	jsk->state |= J1939_SOCK_BOUND;
+
+	spin_lock_bh(&priv->j1939_socks_lock);
+	list_add_tail(&jsk->list, &priv->j1939_socks);
+	spin_unlock_bh(&priv->j1939_socks_lock);
+}
+
+static void j1939_jsk_del(struct j1939_priv *priv, struct j1939_sock *jsk)
+{
+	spin_lock_bh(&priv->j1939_socks_lock);
+	list_del_init(&jsk->list);
+	spin_unlock_bh(&priv->j1939_socks_lock);
+
+	jsk->state &= ~J1939_SOCK_BOUND;
+}
+
 static bool j1939_sk_queue_session(struct j1939_session *session)
 {
 	struct j1939_sock *jsk = j1939_sk(session->sk);
@@ -421,13 +439,8 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 		goto out_dev_put;
 	}
 
-	if (!(jsk->state & J1939_SOCK_BOUND)) {
-		spin_lock_bh(&priv->j1939_socks_lock);
-		list_add_tail(&jsk->list, &priv->j1939_socks);
-		spin_unlock_bh(&priv->j1939_socks_lock);
-
-		jsk->state |= J1939_SOCK_BOUND;
-	}
+	if (!(jsk->state & J1939_SOCK_BOUND))
+		j1939_jsk_add(priv, jsk);
 
  out_dev_put: /* fallthrough */
 	dev_put(ndev);
@@ -544,9 +557,7 @@ static int j1939_sk_release(struct socket *sock)
 		ndev = dev_get_by_index(sock_net(sk), jsk->ifindex);
 		priv = j1939_priv_get_by_ndev(ndev);
 
-		spin_lock_bh(&priv->j1939_socks_lock);
-		list_del_init(&jsk->list);
-		spin_unlock_bh(&priv->j1939_socks_lock);
+		j1939_jsk_del(priv, jsk);
 
 		j1939_local_ecu_put(priv, jsk->addr.src_name,
 				    jsk->addr.sa);
-- 
2.20.1




[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux