From: Peter Hurley <peter@hurleysoftware.com>
To: Gianluca Anzolin <gianluca@sottospazio.it>
Cc: gustavo@padovan.org, linux-bluetooth@vger.kernel.org,
marcel@holtmann.org
Subject: Re: [PATCH 3/8] Move device initialization and shutdown to tty_port_operations
Date: Tue, 16 Jul 2013 16:48:22 -0400 [thread overview]
Message-ID: <51E5B196.7010704@hurleysoftware.com> (raw)
In-Reply-To: <1373661649-1385-3-git-send-email-gianluca@sottospazio.it>
On 07/12/2013 04:40 PM, Gianluca Anzolin wrote:
> Move the device initialization from rfcomm_tty_open to the .activate function of
> tty_port.
>
> At the same time move also the device shutdown from rfcomm_tty_close to the
> .shutdown function of tty_port.
This patch should be merged with patch 5/8 to maintain bisectability.
Otherwise, the .activate() and .shutdown() methods will not be called.
> Signed-off-by: Gianluca Anzolin <gianluca@sottospazio.it>
> ---
> net/bluetooth/rfcomm/tty.c | 120 ++++++++++++++++++++++++++++-----------------
> 1 file changed, 75 insertions(+), 45 deletions(-)
>
> diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
> index ff60171..9b0b064 100644
> --- a/net/bluetooth/rfcomm/tty.c
> +++ b/net/bluetooth/rfcomm/tty.c
> @@ -149,8 +149,80 @@ static void rfcomm_tty_copy_pending(struct rfcomm_dev *dev)
> tty_flip_buffer_push(&dev->port);
> }
>
> +/*
> + * Do the device-specific initialization by opening the DLC and waiting for
> + * a connection.
> + */
> +static int rfcomm_dev_activate(struct tty_port *port, struct tty_struct *tty)
> +{
> + DECLARE_WAITQUEUE(wait, current);
> + struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
> + struct rfcomm_dlc *dlc = dev->dlc;
> + int err;
> +
> + err = rfcomm_dlc_open(dlc, &dev->src, &dev->dst, dev->channel);
> + if (err < 0)
> + goto error_no_dlc;
> +
> + /* Wait for DLC to connect */
> + add_wait_queue(&dev->wait, &wait);
> + while (1) {
> + set_current_state(TASK_INTERRUPTIBLE);
> +
> + if (dlc->state == BT_CLOSED) {
> + err = -dev->err;
> + break;
> + }
> +
> + if (dlc->state == BT_CONNECTED)
> + break;
Please consider moving these dlc->state tests into a
.carrier_raised() port method (this is what the gsm
driver does). Then this wait loop could go away.
> +
> + if (signal_pending(current)) {
> + err = -EINTR;
> + break;
> + }
> +
> + tty_unlock(tty);
> + schedule();
> + tty_lock(tty);
> + }
> + set_current_state(TASK_RUNNING);
> + remove_wait_queue(&dev->wait, &wait);
> +
> + if (err < 0)
> + goto error_no_connection;
> +
> + device_move(dev->tty_dev, rfcomm_get_device(dev),
> + DPM_ORDER_DEV_AFTER_PARENT);
> +
> + rfcomm_tty_copy_pending(dev);
> + rfcomm_dlc_unthrottle(dlc);
> + return 0;
> +
> +error_no_connection:
> + rfcomm_dlc_close(dlc, err);
> +error_no_dlc:
> + return err;
> +}
> +
> +/*
> + * Undo the device initialization by closing the DLC
> + */
> +static void rfcomm_dev_shutdown(struct tty_port *port)
> +{
> + struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
> +
> + if (dev->tty_dev->parent)
> + device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
> +
> + /* Close DLC */
> + rfcomm_dlc_close(dev->dlc, 0);
> +}
> +
> static const struct tty_port_operations rfcomm_port_ops = {
> .destruct = rfcomm_dev_destruct,
> + .activate = rfcomm_dev_activate,
> + .shutdown = rfcomm_dev_shutdown,
> };
>
> static struct rfcomm_dev *__rfcomm_dev_get(int id)
> @@ -647,11 +719,10 @@ static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig)
> /* ---- TTY functions ---- */
> static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
> {
> - DECLARE_WAITQUEUE(wait, current);
> struct rfcomm_dev *dev;
> struct rfcomm_dlc *dlc;
> unsigned long flags;
> - int err, id;
> + int id;
>
> id = tty->index;
>
> @@ -685,44 +756,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
> rfcomm_dlc_unlock(dlc);
> set_bit(RFCOMM_TTY_ATTACHED, &dev->flags);
>
> - err = rfcomm_dlc_open(dlc, &dev->src, &dev->dst, dev->channel);
> - if (err < 0)
> - return err;
> -
> - /* Wait for DLC to connect */
> - add_wait_queue(&dev->wait, &wait);
> - while (1) {
> - set_current_state(TASK_INTERRUPTIBLE);
> -
> - if (dlc->state == BT_CLOSED) {
> - err = -dev->err;
> - break;
> - }
> -
> - if (dlc->state == BT_CONNECTED)
> - break;
> -
> - if (signal_pending(current)) {
> - err = -EINTR;
> - break;
> - }
> -
> - tty_unlock(tty);
> - schedule();
> - tty_lock(tty);
> - }
> - set_current_state(TASK_RUNNING);
> - remove_wait_queue(&dev->wait, &wait);
> -
> - if (err == 0)
> - device_move(dev->tty_dev, rfcomm_get_device(dev),
> - DPM_ORDER_DEV_AFTER_PARENT);
> -
> - rfcomm_tty_copy_pending(dev);
> -
> - rfcomm_dlc_unthrottle(dev->dlc);
> -
> - return err;
> + return 0;
> }
>
> static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
> @@ -739,12 +773,8 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
> spin_lock_irqsave(&dev->port.lock, flags);
> if (!--dev->port.count) {
> spin_unlock_irqrestore(&dev->port.lock, flags);
> - 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);
>
> + /* detach the TTY */
> clear_bit(RFCOMM_TTY_ATTACHED, &dev->flags);
>
> rfcomm_dlc_lock(dev->dlc);
>
next prev parent reply other threads:[~2013-07-16 20:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-12 20:40 [PATCH 1/8] Take proper tty references in net/bluetooth/rfcomm/tty.c Gianluca Anzolin
2013-07-12 20:40 ` [PATCH 2/8] Move functions before the definition of rfcomm_port_ops Gianluca Anzolin
2013-07-16 15:14 ` Peter Hurley
2013-07-12 20:40 ` [PATCH 3/8] Move device initialization and shutdown to tty_port_operations Gianluca Anzolin
2013-07-16 20:48 ` Peter Hurley [this message]
2013-07-20 7:10 ` Gianluca Anzolin
2013-07-20 14:11 ` Peter Hurley
2013-07-21 8:08 ` Gianluca Anzolin
2013-07-21 17:04 ` Peter Hurley
2013-07-21 17:31 ` Gianluca Anzolin
2013-07-12 20:40 ` [PATCH 4/8] Move tty initialization and cleanup out of open/close Gianluca Anzolin
2013-07-16 19:07 ` Peter Hurley
2013-07-12 20:40 ` [PATCH 5/8] Use the tty_port_* functions in tty_open/tty_close/tty_hangup Gianluca Anzolin
2013-07-16 20:51 ` Peter Hurley
2013-07-17 8:03 ` Gianluca Anzolin
2013-07-12 20:40 ` [PATCH 6/8] Fix the reference counting of tty_port Gianluca Anzolin
2013-07-17 14:02 ` Peter Hurley
2013-07-17 17:05 ` Gianluca Anzolin
2013-07-17 18:10 ` Peter Hurley
2013-07-18 12:45 ` Peter Hurley
2013-07-18 14:13 ` Gianluca Anzolin
2013-07-18 15:19 ` Peter Hurley
2013-07-12 20:40 ` [PATCH 7/8] Avoid a circular dependency between dev and dev->dlc Gianluca Anzolin
2013-07-12 20:40 ` [PATCH 8/8] Add module_put in rfcomm_dev_add error path Gianluca Anzolin
2013-07-17 15:20 ` Peter Hurley
2013-07-16 14:53 ` [PATCH 1/8] Take proper tty references in net/bluetooth/rfcomm/tty.c 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=51E5B196.7010704@hurleysoftware.com \
--to=peter@hurleysoftware.com \
--cc=gianluca@sottospazio.it \
--cc=gustavo@padovan.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.