From: Gianluca Anzolin <gianluca@sottospazio.it>
To: Peter Hurley <peter@hurleysoftware.com>
Cc: Alexander Holler <holler@ahsoftware.de>,
marcel@holtmann.org, Gustavo Padovan <gustavo@padovan.org>,
linux-bluetooth@vger.kernel.org, gregkh@linuxfoundation.org,
jslaby@suse.cz, linux-kernel@vger.kernel.org
Subject: Re: [REGRESSION] rfcomm (userland) broken by commit 29cd718b
Date: Mon, 16 Dec 2013 22:15:42 +0100 [thread overview]
Message-ID: <20131216211542.GA20419@sottospazio.it> (raw)
In-Reply-To: <20131216205858.GA20119@sottospazio.it>
[-- Attachment #1: Type: text/plain, Size: 2234 bytes --]
On Mon, Dec 16, 2013 at 09:58:58PM +0100, Gianluca Anzolin wrote:
> On Mon, Dec 16, 2013 at 09:27:20PM +0100, Gianluca Anzolin wrote:
> > On Mon, Dec 16, 2013 at 09:20:44PM +0100, Gianluca Anzolin wrote:
> > > On Mon, Dec 16, 2013 at 02:34:12PM -0500, Peter Hurley wrote:
> > > >
> > > > This solution is acceptable to me, but I think the comment should briefly
> > > > explain why this fix is necessary, and the changelog should explain why in detail.
> > > >
> > > > Perhaps with a fixme comment that rfcomm_tty_install() should just take over
> > > > the port reference (instead of adding one) and rfcomm_tty_cleanup() should
> > > > conditionally release on RFCOMM_RELEASE_ONHUP.
> > > >
> > > > Because then:
> > > > 1) this fix would not be necessary.
> > > > 2) the release in rfcomm_tty_hangup() would not be necessary
> > > > 3) the second release in rfcomm_release_dev would not be necessary
> > > > 4) the RFCOMM_TTY_RELEASED bit could be removed
> > > >
> > > >
> > > > Regards,
> > > > Peter Hurley
> > >
> > > Taking over the refcount in the install method would certainly look better. I'm
> > > going to test it ASAP :D
> > >
> > > But why getting rid of the release in in rfcomm_tty_hangup()?
> > > We could lose the bluetooth connection at any time and the dlc callback
> > > would have to hangup the tty (and release the port if necessary).
> > >
> > > Also the RFCOMM_TTY_RELEASED bit should still be necessary if the port is
> > > created without the RFCOMM_RELEASE_ONHUP flag.
> > >
> > > Besides any process could release the port behind us (with the command rfcomm
> > > release rfcomm1 for example).
> > >
> > > Gianluca
> >
> > Nevermind I figured it out the reason...
>
> I'm testing the attached patch ATM, which does what you described. It works
> very well.
>
> It doesn't remove the RFCOMM_TTY_RELEASE flag yet, another patch should remove
> that bit.
ok, replying to myself again (sorry for that). RFCOMM_TTY_RELEASE cannot go
away. We have still to manage the case where the port is opened without
RFCOMM_RELEASE_ONHUP.
This last patch does release the port in that situation.
Tested with:
# rfcomm bind 1 <addr>
# rfcomm release 1
and with
# rfcomm connect 1 <addr>
Thanks,
Gianluca
[-- Attachment #2: rfc3.patch --]
[-- Type: text/x-diff, Size: 1319 bytes --]
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 84fcf9f..0357dcf 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -437,7 +437,8 @@ static int rfcomm_release_dev(void __user *arg)
tty_kref_put(tty);
}
- if (!test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags))
+ if (!test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags) &&
+ !test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags))
tty_port_put(&dev->port);
tty_port_put(&dev->port);
@@ -673,6 +674,14 @@ static int rfcomm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
if (err)
rfcomm_tty_cleanup(tty);
+ /* take over the tty_port reference if it was created with the
+ * flag RFCOMM_RELEASE_ONHUP. This will force the release of the port
+ * when the last process closes the tty. This behaviour is expected by
+ * userspace.
+ */
+ if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags))
+ tty_port_put(&dev->port);
+
return err;
}
@@ -1010,10 +1019,6 @@ static void rfcomm_tty_hangup(struct tty_struct *tty)
BT_DBG("tty %p dev %p", tty, dev);
tty_port_hangup(&dev->port);
-
- if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags) &&
- !test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags))
- tty_port_put(&dev->port);
}
static int rfcomm_tty_tiocmget(struct tty_struct *tty)
next prev parent reply other threads:[~2013-12-16 21:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-27 16:28 [PATCH] rfcomm: don't release the port in rfcomm_dev_state_change() Gianluca Anzolin
2013-09-18 1:19 ` Peter Hurley
2013-09-19 16:24 ` Gustavo Padovan
2013-12-12 20:11 ` [REGRESSION] rfcomm (userland) broken by commit 29cd718b Alexander Holler
2013-12-12 20:36 ` Peter Hurley
2013-12-12 23:35 ` Alexander Holler
2013-12-15 11:24 ` Gianluca Anzolin
2013-12-15 14:03 ` Peter Hurley
2013-12-15 15:08 ` Gianluca Anzolin
2013-12-15 17:54 ` Alexander Holler
2013-12-16 19:34 ` Peter Hurley
2013-12-16 20:20 ` Gianluca Anzolin
2013-12-16 20:27 ` Gianluca Anzolin
2013-12-16 20:58 ` Gianluca Anzolin
2013-12-16 21:15 ` Gianluca Anzolin [this message]
2013-12-24 13:21 ` Alexander Holler
2013-12-27 23:01 ` Benson Chow
2013-12-28 8:44 ` Gianluca Anzolin
2014-01-04 4:32 ` Benson Chow
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=20131216211542.GA20419@sottospazio.it \
--to=gianluca@sottospazio.it \
--cc=gregkh@linuxfoundation.org \
--cc=gustavo@padovan.org \
--cc=holler@ahsoftware.de \
--cc=jslaby@suse.cz \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=peter@hurleysoftware.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).