linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dean Jenkins <Dean_Jenkins@mentor.com>
To: Szymon Janc <szymon.janc@tieto.com>
Cc: <linux-bluetooth@vger.kernel.org>, <marcel@holtmann.org>,
	<gustavo@padovan.org>, <johan.hedberg@gmail.com>,
	<Joshua_Frkuska@mentor.com>
Subject: Re: [PATCH v1 3/7] Bluetooth: Unwind l2cap_sock_shutdown()
Date: Tue, 9 Jun 2015 11:13:32 +0100	[thread overview]
Message-ID: <5576BC4C.9020004@mentor.com> (raw)
In-Reply-To: <3313217.oq1TWQmj1d@leonov>

Hi Szymon,

On 09/06/15 10:55, Szymon Janc wrote:
> Hi Dean,
>
> On Saturday 06 of June 2015 00:11:12 Dean Jenkins wrote:
>> l2cap_sock_shutdown() is designed to only action shutdown
>> of the channel when shutdown is not already in progress.
>> Therefore, reorganise the code flow by adding a goto
>> to jump to the end of function handling when shutdown is
>> already being actioned. This removes one level of code
>> indentation and make the code more readable.
>>
>> Signed-off-by: Dean Jenkins <Dean_Jenkins@mentor.com>
>> ---
>>   net/bluetooth/l2cap_sock.c | 44
>> ++++++++++++++++++++++++-------------------- 1 file changed, 24
>> insertions(+), 20 deletions(-)
>>
>> diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
>> index c909f45..8550886 100644
>> --- a/net/bluetooth/l2cap_sock.c
>> +++ b/net/bluetooth/l2cap_sock.c
>> @@ -1099,6 +1099,13 @@ static int l2cap_sock_shutdown(struct socket *sock,
>> int how) if (!sk)
>>   		return 0;
>>
>> +	lock_sock(sk);
>> +
>> +	if (sk->sk_shutdown)
>> +		goto shutdown_already;
>> +
>> +	sk->sk_shutdown = SHUTDOWN_MASK;
>> +
>>   	/* prevent sk structure from being freed whilst unlocked */
>>   	sock_hold(sk);
>>
>> @@ -1113,30 +1120,21 @@ static int l2cap_sock_shutdown(struct socket *sock,
>> int how) mutex_lock(&conn->chan_lock);
>>
>>   	l2cap_chan_lock(chan);
>> -	lock_sock(sk);
>>
>> -	if (!sk->sk_shutdown) {
>> -		if (chan->mode == L2CAP_MODE_ERTM &&
>> -		    chan->unacked_frames > 0 &&
>> -		    chan->state == BT_CONNECTED)
>> -			err = __l2cap_wait_ack(sk, chan);
>> +	if (chan->mode == L2CAP_MODE_ERTM &&
>> +	    chan->unacked_frames > 0 &&
>> +	    chan->state == BT_CONNECTED)
>> +		err = __l2cap_wait_ack(sk, chan);
>>
>> -		sk->sk_shutdown = SHUTDOWN_MASK;
>> -
>> -		release_sock(sk);
>> -		l2cap_chan_close(chan, 0);
>> -		lock_sock(sk);
>> -
>> -		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
>> -		    !(current->flags & PF_EXITING))
>> -			err = bt_sock_wait_state(sk, BT_CLOSED,
>> -						 sk->sk_lingertime);
>> -	}
>> +	release_sock(sk);
>> +	l2cap_chan_close(chan, 0);
>> +	lock_sock(sk);
>>
>> -	if (!err && sk->sk_err)
>> -		err = -sk->sk_err;
>> +	if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
>> +	    !(current->flags & PF_EXITING))
>> +		err = bt_sock_wait_state(sk, BT_CLOSED,
>> +					 sk->sk_lingertime);
>>
>> -	release_sock(sk);
>>   	l2cap_chan_unlock(chan);
>>
>>   	if (conn)
>> @@ -1146,6 +1144,12 @@ static int l2cap_sock_shutdown(struct socket *sock,
>> int how) l2cap_chan_put(chan);
>>   	sock_put(sk);
> Isn't it possible that sk will be freed here? (at least this is what comment
> from patch 1 suggests).
At this point in the code, lock_sock(sk) is held so it should prevent 
the freeing of sk.
I think my comment is misleading. I will rewrite my comment.

Thanks.
>
>> +shutdown_already:
>> +	if (!err && sk->sk_err)
>> +		err = -sk->sk_err;
>> +
>> +	release_sock(sk);
>> +
>>   	return err;
>>   }


-- 
Dean Jenkins
Embedded Software Engineer
Linux Transportation Solutions
Mentor Embedded Software Division
Mentor Graphics (UK) Ltd.


  reply	other threads:[~2015-06-09 10:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-05 23:11 [PATCH v1 0/7] Avoid L2CAP ERTM shutdown hung tasks Dean Jenkins
2015-06-05 23:11 ` [PATCH v1 1/7] Bluetooth: L2CAP ERTM shutdown protect sk and chan Dean Jenkins
2015-06-05 23:11 ` [PATCH v1 2/7] Bluetooth: Make __l2cap_wait_ack more efficient Dean Jenkins
2015-06-05 23:11 ` [PATCH v1 3/7] Bluetooth: Unwind l2cap_sock_shutdown() Dean Jenkins
2015-06-09  9:55   ` Szymon Janc
2015-06-09 10:13     ` Dean Jenkins [this message]
2015-06-05 23:11 ` [PATCH v1 4/7] Bluetooth: l2cap_sock_shutdown() remove mutex_lock calls Dean Jenkins
2015-06-05 23:11 ` [PATCH v1 5/7] Bluetooth: l2cap_sock_shutdown() reduce scope of chan locking Dean Jenkins
2015-06-05 23:11 ` [PATCH v1 6/7] Bluetooth: Add BT_DBG to l2cap_sock_shutdown() Dean Jenkins
2015-06-05 23:11 ` [PATCH v1 7/7] Bluetooth: __l2cap_wait_ack() limit max waiting time Dean Jenkins
2015-06-06  4:21   ` Marcel Holtmann
2015-06-10 10:31     ` Dean Jenkins
2015-06-10 11:18       ` Marcel Holtmann
2015-06-06  4:13 ` [PATCH v1 0/7] Avoid L2CAP ERTM shutdown hung tasks Marcel Holtmann
2015-10-07 14:09   ` Luiz Augusto von Dentz
2015-10-07 14:43     ` Dean Jenkins
2015-10-08  8:59       ` Luiz Augusto von Dentz

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=5576BC4C.9020004@mentor.com \
    --to=dean_jenkins@mentor.com \
    --cc=Joshua_Frkuska@mentor.com \
    --cc=gustavo@padovan.org \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=szymon.janc@tieto.com \
    /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).