linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Hurley <peter@hurleysoftware.com>
To: Gianluca Anzolin <gianluca@sottospazio.it>
Cc: gustavo@padovan.org, marcel@holtmann.org,
	linux-bluetooth@vger.kernel.org, gregkh@linuxfoundation.org,
	jslaby@suse.cz
Subject: Re: [PATCH v4 3/6] rfcomm: Move the tty initialization and cleanup out of open/close
Date: Fri, 26 Jul 2013 16:04:32 -0400	[thread overview]
Message-ID: <51F2D650.4080706@hurleysoftware.com> (raw)
In-Reply-To: <1374859138-19467-4-git-send-email-gianluca@sottospazio.it>

On 07/26/2013 01:18 PM, Gianluca Anzolin wrote:
> Move the tty_struct initialization from rfcomm_tty_open() to
> rfcomm_tty_install() and do the same for the cleanup moving the code from
> rfcomm_tty_close() to rfcomm_tty_cleanup().
>
> Add also extra error handling in rfcomm_tty_install() because, unlike
> .open()/.close(), .cleanup() is not called if .install() fails.
>
> Signed-off-by: Gianluca Anzolin <gianluca@sottospazio.it>
> ---
>   net/bluetooth/rfcomm/tty.c | 108 +++++++++++++++++++++++++++++----------------
>   1 file changed, 69 insertions(+), 39 deletions(-)
>
> diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
> index 9c0e142..bfaa444 100644
> --- a/net/bluetooth/rfcomm/tty.c
> +++ b/net/bluetooth/rfcomm/tty.c
> @@ -633,49 +633,64 @@ static void rfcomm_tty_copy_pending(struct rfcomm_dev *dev)
>   		tty_flip_buffer_push(&dev->port);
>   }
>
> -static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
> +/* do the reverse of install, clearing the tty fields and releasing the
> + * reference to tty_port
> + */
> +static void rfcomm_tty_cleanup(struct tty_struct *tty)
> +{
> +	struct rfcomm_dev *dev = tty->driver_data;
> +
> +	if (dev->tty_dev->parent)
> +		device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
> +
> +	/* Close DLC and dettach TTY */
> +	rfcomm_dlc_close(dev->dlc, 0);
> +
> +	clear_bit(RFCOMM_TTY_ATTACHED, &dev->flags);
> +
> +	rfcomm_dlc_lock(dev->dlc);
> +	tty->driver_data = NULL;
> +	dev->port.tty = NULL;
> +	rfcomm_dlc_unlock(dev->dlc);
> +
> +	tty_port_put(&dev->port);
> +}
> +
> +/* we acquire the tty_port reference since it's here the tty is first used
> + * by setting the termios. We also populate the driver_data field and install
> + * the tty port
> + */
> +static int rfcomm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
>   {
>   	DECLARE_WAITQUEUE(wait, current);
>   	struct rfcomm_dev *dev;
>   	struct rfcomm_dlc *dlc;
> -	unsigned long flags;
> -	int err, id;
> -
> -	id = tty->index;
> +	int err;
>
> -	BT_DBG("tty %p id %d", tty, id);
> -
> -	/* We don't leak this refcount. For reasons which are not entirely
> -	   clear, the TTY layer will call our ->close() method even if the
> -	   open fails. We decrease the refcount there, and decreasing it
> -	   here too would cause breakage. */
> -	dev = rfcomm_dev_get(id);
> +	dev = rfcomm_dev_get(tty->index);
>   	if (!dev)
>   		return -ENODEV;
>


>   	BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
>   	       dev->channel, dev->port.count);

This debug message is probably more useful in rfcomm_tty_open().
But if you decide to leave it here, the port count will always be 0 so
that field should be removed.

Regards,
Peter Hurley

  reply	other threads:[~2013-07-26 20:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-26 17:18 [PATCH v4 0/6] rfcomm: Implement rfcomm as a proper tty_port Gianluca Anzolin
2013-07-26 17:18 ` [PATCH v4 1/6] rfcomm: Take proper tty_struct references Gianluca Anzolin
2013-07-26 17:18 ` [PATCH v4 2/6] rfcomm: Remove the device from the list in the destructor Gianluca Anzolin
2013-07-26 17:18 ` [PATCH v4 3/6] rfcomm: Move the tty initialization and cleanup out of open/close Gianluca Anzolin
2013-07-26 20:04   ` Peter Hurley [this message]
2013-07-26 17:18 ` [PATCH v4 4/6] rfcomm: Implement .activate, .shutdown and .carrier_raised methods Gianluca Anzolin
2013-07-26 17:18 ` [PATCH v4 5/6] rfcomm: Fix the reference counting of tty_port Gianluca Anzolin
2013-07-27  0:20   ` Peter Hurley
2013-07-27  4:48     ` Gianluca Anzolin
2013-07-27 12:07       ` Peter Hurley
2013-07-26 17:18 ` [PATCH v4 6/6] rfcomm: Purge the dlc->tx_queue to avoid circular dependency Gianluca Anzolin
2013-07-26 19:56 ` [PATCH v4 0/6] rfcomm: Implement rfcomm as a proper tty_port Peter Hurley

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=51F2D650.4080706@hurleysoftware.com \
    --to=peter@hurleysoftware.com \
    --cc=gianluca@sottospazio.it \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@padovan.org \
    --cc=jslaby@suse.cz \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.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).