linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gustavo Padovan <gustavo@padovan.org>
To: linux-bluetooth@vger.kernel.org
Cc: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Subject: Re: [RFC 3/3] Blueooth: Remove parent socket usage from l2cap_core.c
Date: Thu, 24 May 2012 03:32:35 -0300	[thread overview]
Message-ID: <20120524063235.GE21117@joana> (raw)
In-Reply-To: <1337839374-20443-3-git-send-email-gustavo@padovan.org>

This is Bluetooth: and not Blueooth:

* Gustavo Padovan <gustavo@padovan.org> [2012-05-24 03:02:54 -0300]:

> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> 
> We can lock the parent lock only inside the new_connection() call, then we
> just use the l2cap_chan_lock() in core code.
> 
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> ---
>  net/bluetooth/l2cap_core.c |   16 ++++++----------
>  net/bluetooth/l2cap_sock.c |    9 ++++++++-
>  2 files changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 5ff294f9..314ce74 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -1139,7 +1139,7 @@ static struct l2cap_chan *l2cap_global_chan_by_scid(int state, u16 cid,
>  
>  static void l2cap_le_conn_ready(struct l2cap_conn *conn)
>  {
> -	struct sock *parent, *sk;
> +	struct sock *sk;
>  	struct l2cap_chan *chan, *pchan;
>  
>  	BT_DBG("");
> @@ -1150,9 +1150,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
>  	if (!pchan)
>  		return;
>  
> -	parent = pchan->sk;
> -
> -	lock_sock(parent);
> +	l2cap_chan_lock(pchan);
>  
>  	chan = pchan->ops->new_connection(pchan->data);
>  	if (!chan)
> @@ -1170,7 +1168,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
>  	l2cap_chan_ready(chan);
>  
>  clean:
> -	release_sock(parent);
> +	l2cap_chan_unlock(pchan);
>  }
>  
>  static void l2cap_conn_ready(struct l2cap_conn *conn)
> @@ -3308,7 +3306,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
>  	struct l2cap_conn_req *req = (struct l2cap_conn_req *) data;
>  	struct l2cap_conn_rsp rsp;
>  	struct l2cap_chan *chan = NULL, *pchan;
> -	struct sock *parent, *sk = NULL;
> +	struct sock *sk = NULL;
>  	int result, status = L2CAP_CS_NO_INFO;
>  
>  	u16 dcid = 0, scid = __le16_to_cpu(req->scid);
> @@ -3323,10 +3321,8 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
>  		goto sendresp;
>  	}
>  
> -	parent = pchan->sk;
> -
>  	mutex_lock(&conn->chan_lock);
> -	lock_sock(parent);
> +	l2cap_chan_lock(pchan);
>  
>  	/* Check if the ACL is secure enough (if not SDP) */
>  	if (psm != cpu_to_le16(0x0001) &&
> @@ -3388,7 +3384,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
>  	}
>  
>  response:
> -	release_sock(parent);
> +	l2cap_chan_unlock(pchan);
>  	mutex_unlock(&conn->chan_lock);
>  
>  sendresp:
> diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
> index f4c3e2c..be3e934 100644
> --- a/net/bluetooth/l2cap_sock.c
> +++ b/net/bluetooth/l2cap_sock.c
> @@ -900,16 +900,21 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(void *data)
>  {
>  	struct sock *sk, *parent = data;
>  
> +	lock_sock(parent);
> +
>  	/* Check for backlog size */
>  	if (sk_acceptq_is_full(parent)) {
>  		BT_DBG("backlog full %d", parent->sk_ack_backlog);
> +		release_sock(parent);
>  		return NULL;
>  	}
>  
>  	sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP,
>  								GFP_ATOMIC);
> -	if (!sk)
> +	if (!sk) {
> +		release_sock(parent);
>  		return NULL;
> +	}
>  
>  	bt_sock_reclassify_lock(sk, BTPROTO_L2CAP);
>  
> @@ -917,6 +922,8 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(void *data)
>  
>  	bt_accept_enqueue(parent, sk);
>  
> +	release_sock(parent);
> +
>  	return l2cap_pi(sk)->chan;
>  }
>  
> -- 
> 1.7.10.1
> 

	Gustavo

  reply	other threads:[~2012-05-24  6:32 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-24  1:12 [RFC 0/8] Another step in l2cap_core/sock separation Gustavo Padovan
2012-05-24  1:12 ` [RFC 1/8] Bluetooth: Move clean up code and set of SOCK_ZAPPED to l2cap_sock.c Gustavo Padovan
2012-05-24  1:12   ` [RFC 2/8] Bluetooth: Remove extra l2cap_state_change(BT_CONNECTED) Gustavo Padovan
2012-05-24  1:12     ` [RFC 3/8] Bluetooth: Add l2cap_chan->ops->ready() Gustavo Padovan
2012-05-24  1:12       ` [RFC 4/8] Bluetooth: Use l2cap_chan_ready() in LE path Gustavo Padovan
2012-05-24  1:12         ` [RFC 5/8] Bluetooth: Use chan->state instead of sk->sk_state Gustavo Padovan
2012-05-24  1:12           ` [RFC 6/8] Bluetooth: Move check for backlog size to l2cap_sock.c Gustavo Padovan
2012-05-24  1:12             ` [RFC 7/8] Bluetooth: Create DEFER_SETUP flag in conf_state Gustavo Padovan
2012-05-24  1:12               ` [RFC 8/8] Bluetooth: Add chan->ops->authorize Gustavo Padovan
2012-05-24  6:02                 ` [RFC 1/3] Bluetooth: check for already existent channel before create new one Gustavo Padovan
2012-05-24  6:02                   ` [RFC 2/3] Bluetooth: Move bt_accept_enqueue() call to l2cap_sock.c Gustavo Padovan
2012-05-24  6:02                     ` [RFC 3/3] Blueooth: Remove parent socket usage from l2cap_core.c Gustavo Padovan
2012-05-24  6:32                       ` Gustavo Padovan [this message]
2012-05-24  7:00                       ` [RFC 1/2] Bluetooth: Create chan->ops->set_err() Gustavo Padovan
2012-05-24  7:00                         ` [RFC 2/2] Bluetooth: Remove last usage of sk->sk_state_change() Gustavo Padovan
2012-05-24  8:30                           ` Andrei Emeltchenko
2012-05-24 17:06                             ` Gustavo Padovan
2012-05-24  8:26                         ` [RFC 1/2] Bluetooth: Create chan->ops->set_err() Andrei Emeltchenko
2012-05-24 17:04                           ` Gustavo Padovan
2012-05-24 17:18                             ` Mat Martineau
2012-05-25  7:07                               ` Andrei Emeltchenko
2012-05-24  9:22                       ` [RFC 3/3] Blueooth: Remove parent socket usage from l2cap_core.c Andrei Emeltchenko
2012-05-24  9:24                     ` [RFC 2/3] Bluetooth: Move bt_accept_enqueue() call to l2cap_sock.c Andrei Emeltchenko
2012-05-24 17:09                       ` Gustavo Padovan
2012-05-24 17:36                     ` Mat Martineau
2012-05-24  9:27                   ` [RFC 1/3] Bluetooth: check for already existent channel before create new one Andrei Emeltchenko
2012-05-24  9:55                 ` [RFC 8/8] Bluetooth: Add chan->ops->authorize Andrei Emeltchenko
2012-05-24 17:08                   ` Gustavo Padovan
2012-05-24 17:10                 ` Mat Martineau
2012-05-24  9:50               ` [RFC 7/8] Bluetooth: Create DEFER_SETUP flag in conf_state Andrei Emeltchenko
2012-05-24 17:01                 ` Gustavo Padovan
2012-05-24  9:45             ` [RFC 6/8] Bluetooth: Move check for backlog size to l2cap_sock.c Andrei Emeltchenko
2012-05-24 16:57               ` Gustavo Padovan
2012-05-24  9:39       ` [RFC 3/8] Bluetooth: Add l2cap_chan->ops->ready() Andrei Emeltchenko
2012-05-24 10:23         ` Andrei Emeltchenko
2012-05-24 11:17           ` Ulisses Furquim
2012-05-24 11:30             ` Andrei Emeltchenko
2012-05-24 11:31               ` Ulisses Furquim
2012-05-24 11:37                 ` Andrei Emeltchenko
2012-05-24 17:48                   ` Mat Martineau
2012-05-24 17:53                     ` Ulisses Furquim
2012-05-24 18:48               ` Vinicius Costa Gomes
2012-05-24  9:38     ` [RFC 2/8] Bluetooth: Remove extra l2cap_state_change(BT_CONNECTED) Andrei Emeltchenko
2012-05-24  9:35   ` [RFC 1/8] Bluetooth: Move clean up code and set of SOCK_ZAPPED to l2cap_sock.c Andrei Emeltchenko
2012-05-24 16:56     ` Gustavo Padovan
2012-05-24 17:14       ` Gustavo Padovan
2012-05-24 17:25         ` Vinicius Costa Gomes
2012-05-24  6:12 ` [RFC 0/8] Another step in l2cap_core/sock separation Gustavo Padovan
2012-05-24 10:02 ` Andrei Emeltchenko
2012-05-24 16:43   ` Gustavo Padovan
2012-05-24 17:55   ` Mat Martineau

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=20120524063235.GE21117@joana \
    --to=gustavo@padovan.org \
    --cc=gustavo.padovan@collabora.co.uk \
    --cc=linux-bluetooth@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).