Linux bluetooth development
 help / color / mirror / Atom feed
From: Andrei Emeltchenko <andrei.emeltchenko.news@gmail.com>
To: "Gustavo F. Padovan" <padovan@profusion.mobi>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [RFC 10/22] Bluetooth: convert chan_lock to mutex
Date: Mon, 19 Dec 2011 11:58:39 +0200	[thread overview]
Message-ID: <20111219095837.GB3982@aemeltch-MOBL1> (raw)
In-Reply-To: <1324157382-1815-11-git-send-email-padovan@profusion.mobi>

Hi Gustavo,

On Sat, Dec 17, 2011 at 07:29:30PM -0200, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
> 
> spin lock doesn't fit ok anymore on the new code based on workqueues.
> 
> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
> ---
>  include/net/bluetooth/l2cap.h |    2 +-
>  net/bluetooth/l2cap_core.c    |   52 ++++++++++++++++++++--------------------
>  2 files changed, 27 insertions(+), 27 deletions(-)
> 
> diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
> index 03be911..a175091 100644
> --- a/include/net/bluetooth/l2cap.h
> +++ b/include/net/bluetooth/l2cap.h
> @@ -536,7 +536,7 @@ struct l2cap_conn {
>  	struct smp_chan *smp_chan;
>  
>  	struct list_head chan_l;
> -	rwlock_t	chan_lock;
> +	struct mutex	chan_lock;
>  };
>  
>  #define L2CAP_INFO_CL_MTU_REQ_SENT	0x01
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 31c94fd..5c5948f 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -115,11 +115,11 @@ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 ci
>  {
>  	struct l2cap_chan *c;
>  
> -	read_lock(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  	c = __l2cap_get_chan_by_scid(conn, cid);
>  	if (c)
>  		lock_sock(c->sk);
> -	read_unlock(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  	return c;
>  }
>  
> @@ -138,11 +138,11 @@ static inline struct l2cap_chan *l2cap_get_chan_by_ident(struct l2cap_conn *conn
>  {
>  	struct l2cap_chan *c;
>  
> -	read_lock(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  	c = __l2cap_get_chan_by_ident(conn, ident);
>  	if (c)
>  		lock_sock(c->sk);
> -	read_unlock(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  	return c;
>  }
>  
> @@ -381,9 +381,9 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
>  
>  	if (conn) {
>  		/* Delete from channel list */
> -		write_lock_bh(&conn->chan_lock);
> +		mutex_lock(&conn->chan_lock);
>  		list_del(&chan->list);
> -		write_unlock_bh(&conn->chan_lock);
> +		mutex_unlock(&conn->chan_lock);
>  		chan_put(chan);
>  
>  		chan->conn = NULL;
> @@ -754,7 +754,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
>  
>  	BT_DBG("conn %p", conn);
>  
> -	read_lock(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  
>  	list_for_each_entry_safe(chan, tmp, &conn->chan_l, list) {
>  		struct sock *sk = chan->sk;
> @@ -780,9 +780,9 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
>  					&chan->conf_state)) {
>  				/* l2cap_chan_close() calls list_del(chan)
>  				 * so release the lock */
> -				read_unlock(&conn->chan_lock);
> +				mutex_unlock(&conn->chan_lock);
>  				l2cap_chan_close(chan, ECONNRESET);
> -				read_lock(&conn->chan_lock);
> +				utex_lock(&conn->chan_lock);

Something corrupted here?

Best regards 
Andrei Emeltchenko 

>  				bh_unlock_sock(sk);
>  				continue;
>  			}
> @@ -838,7 +838,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
>  		bh_unlock_sock(sk);
>  	}
>  
> -	read_unlock(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  }
>  
>  /* Find socket with cid and source bdaddr.
> @@ -903,7 +903,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
>  
>  	sk = chan->sk;
>  
> -	write_lock_bh(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  
>  	hci_conn_hold(conn->hcon);
>  
> @@ -919,7 +919,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
>  	l2cap_state_change(chan, BT_CONNECTED);
>  	parent->sk_data_ready(parent, 0);
>  
> -	write_unlock_bh(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  
>  clean:
>  	release_sock(parent);
> @@ -954,7 +954,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
>  	if (conn->hcon->out && conn->hcon->type == LE_LINK)
>  		smp_conn_security(conn, conn->hcon->pending_sec_level);
>  
> -	read_lock(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  
>  	list_for_each_entry(chan, &conn->chan_l, list) {
>  		struct sock *sk = chan->sk;
> @@ -976,7 +976,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
>  		bh_unlock_sock(sk);
>  	}
>  
> -	read_unlock(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  }
>  
>  /* Notify sockets that we cannot guaranty reliability anymore */
> @@ -986,7 +986,7 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err)
>  
>  	BT_DBG("conn %p", conn);
>  
> -	read_lock(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  
>  	list_for_each_entry(chan, &conn->chan_l, list) {
>  		struct sock *sk = chan->sk;
> @@ -995,7 +995,7 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err)
>  			sk->sk_err = err;
>  	}
>  
> -	read_unlock(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  }
>  
>  static void l2cap_info_timeout(unsigned long arg)
> @@ -1086,7 +1086,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
>  	conn->feat_mask = 0;
>  
>  	spin_lock_init(&conn->lock);
> -	rwlock_init(&conn->chan_lock);
> +	mutex_init(&conn->chan_lock);
>  
>  	INIT_LIST_HEAD(&conn->chan_l);
>  
> @@ -1104,9 +1104,9 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
>  
>  static inline void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
>  {
> -	write_lock_bh(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  	__l2cap_chan_add(conn, chan);
> -	write_unlock_bh(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  }
>  
>  /* ---- Socket interface ---- */
> @@ -1771,7 +1771,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
>  
>  	BT_DBG("conn %p", conn);
>  
> -	read_lock(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  	list_for_each_entry(chan, &conn->chan_l, list) {
>  		struct sock *sk = chan->sk;
>  		if (chan->chan_type != L2CAP_CHAN_RAW)
> @@ -1787,7 +1787,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
>  		if (chan->ops->recv(chan->data, nskb))
>  			kfree_skb(nskb);
>  	}
> -	read_unlock(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  }
>  
>  /* ---- L2CAP signalling commands ---- */
> @@ -2587,11 +2587,11 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
>  
>  	sk = chan->sk;
>  
> -	write_lock_bh(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  
>  	/* Check if we already have channel with that dcid */
>  	if (__l2cap_get_chan_by_dcid(conn, scid)) {
> -		write_unlock_bh(&conn->chan_lock);
> +		mutex_unlock(&conn->chan_lock);
>  		sock_set_flag(sk, SOCK_ZAPPED);
>  		chan->ops->close(chan->data);
>  		goto response;
> @@ -2637,7 +2637,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
>  		status = L2CAP_CS_NO_INFO;
>  	}
>  
> -	write_unlock_bh(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  
>  response:
>  	release_sock(parent);
> @@ -4474,7 +4474,7 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
>  		del_timer(&conn->security_timer);
>  	}
>  
> -	read_lock(&conn->chan_lock);
> +	mutex_lock(&conn->chan_lock);
>  
>  	list_for_each_entry(chan, &conn->chan_l, list) {
>  		struct sock *sk = chan->sk;
> @@ -4554,7 +4554,7 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
>  		bh_unlock_sock(sk);
>  	}
>  
> -	read_unlock(&conn->chan_lock);
> +	mutex_unlock(&conn->chan_lock);
>  
>  	return 0;
>  }
> -- 
> 1.7.6.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2011-12-19  9:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-17 21:29 [RFC 00/22] Bluetooth: change tasklets to workqueue Gustavo F. Padovan
2011-12-17 21:29 ` [RFC 01/22] Bluetooth: Process recv path in a workqueue instead of a tasklet Gustavo F. Padovan
2011-12-17 21:29   ` [RFC 02/22] Bluetooth: Replace spin_lock by mutex in hci_dev Gustavo F. Padovan
2011-12-17 21:29     ` [RFC 03/22] Bluetooth: Use delayed_work for connection timeout Gustavo F. Padovan
2011-12-17 21:29       ` [RFC 04/22] Bluetooth: Use delayed work for advertisiment cache timeout Gustavo F. Padovan
2011-12-17 21:29         ` [RFC 05/22] Bluetooth: hci_conn_auto_accept() doesn't need locking Gustavo F. Padovan
2011-12-17 21:29           ` [RFC 06/22] Bluetooth: Move L2CAP timers to workqueue Gustavo F. Padovan
2011-12-17 21:29             ` [RFC 07/22] Bluetooth: Don't use spin_lock socket lock anymore Gustavo F. Padovan
2011-12-17 21:29               ` [RFC 08/22] Bluetooth: Remove sk_backlog usage from L2CAP Gustavo F. Padovan
2011-12-17 21:29                 ` [RFC 09/22] Bluetooth: move hci_task_lock to mutex Gustavo F. Padovan
2011-12-17 21:29                   ` [RFC 10/22] Bluetooth: convert chan_lock " Gustavo F. Padovan
2011-12-17 21:29                     ` [RFC 11/22] Bluetooth: Use RCU to manipulate chan_list Gustavo F. Padovan
2011-12-17 21:29                       ` [RFC 12/22] Bluetooth: convert conn hash to RCU Gustavo F. Padovan
2011-12-17 21:29                         ` [RFC 13/22] Bluetooth: Don't disable tasklets to call hdev->notify() Gustavo F. Padovan
2011-12-17 21:29                           ` [RFC 14/22] Bluetooth: Move command task to workqueue Gustavo F. Padovan
2011-12-17 21:29                             ` [RFC 15/22] Bluetooth: convert tx_task " Gustavo F. Padovan
2011-12-17 21:29                               ` [RFC 16/22] Bluetooth: convert info timer to delayed_work Gustavo F. Padovan
2011-12-17 21:29                                 ` [RFC 17/22] Bluetooth: remove power_on work_struct Gustavo F. Padovan
2011-12-17 21:29                                   ` [RFC 18/22] Bluetooth: invert locking order in connect path Gustavo F. Padovan
2011-12-17 21:29                                     ` [RFC 19/22] Bluetooth: Change l2cap chan_list to use RCU Gustavo F. Padovan
2011-12-17 21:29                                       ` [RFC 20/22] Bluetooth: move power_off to system workqueue Gustavo F. Padovan
2011-12-17 21:29                                         ` [RFC 21/22] Bluetooth: Use new alloc_workqueue() Gustavo F. Padovan
2011-12-17 21:29                                           ` [RFC 22/22] Bluetooth: Remove work_add and work_del from hci_sysfs Gustavo F. Padovan
2011-12-17 22:15                                       ` [RFC 19/22] Bluetooth: Change l2cap chan_list to use RCU Marcel Holtmann
2011-12-19 10:42                                       ` Andrei Emeltchenko
2011-12-19 13:53                                         ` Gustavo Padovan
2011-12-17 22:13                                   ` [RFC 17/22] Bluetooth: remove power_on work_struct Marcel Holtmann
2012-01-26 13:20                       ` [RFC 11/22] Bluetooth: Use RCU to manipulate chan_list Andrei Emeltchenko
2011-12-19  9:58                     ` Andrei Emeltchenko [this message]
2011-12-19  9:53               ` [RFC 07/22] Bluetooth: Don't use spin_lock socket lock anymore Andrei Emeltchenko
2011-12-19 11:05             ` [RFC 06/22] Bluetooth: Move L2CAP timers to workqueue Andrei Emeltchenko
2011-12-19 12:59               ` Ulisses Furquim
2011-12-17 21:34 ` [RFC 00/22] Bluetooth: change tasklets " Gustavo Padovan
2011-12-17 22:17 ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111219095837.GB3982@aemeltch-MOBL1 \
    --to=andrei.emeltchenko.news@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=padovan@profusion.mobi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox