The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tty: Fix close races in USB serial
Date: Tue, 4 Nov 2008 09:11:28 -0800	[thread overview]
Message-ID: <20081104171128.GB630@kroah.com> (raw)
In-Reply-To: <20081104152916.30344.68193.stgit@localhost.localdomain>

On Tue, Nov 04, 2008 at 03:29:24PM +0000, Alan Cox wrote:
> From: Alan Cox <alan@redhat.com>
> 
> USB serial has always had races where the tty port usage count can hit zero
> during a receive event. The internal locking is a mutex so we can't use
> that in the IRQ handlers.
> 
> With krefs we can tackle this differently but we still need to be careful.
> 
> Signed-off-by: Alan Cox <alan@redhat.com>
> ---
> 
>  drivers/usb/serial/usb-serial.c |   15 ++++++++++-----
>  1 files changed, 10 insertions(+), 5 deletions(-)
> 
> 
> diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
> index 794b5ff..aafa684 100644
> --- a/drivers/usb/serial/usb-serial.c
> +++ b/drivers/usb/serial/usb-serial.c
> @@ -269,15 +269,19 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
>  		return;
>  	}
>  
> -	--port->port.count;
> -	if (port->port.count == 0)
> +	if (port->port.count == 1)
>  		/* only call the device specific close if this
> -		 * port is being closed by the last owner */
> +		 * port is being closed by the last owner. Ensure we do
> +		 * this before we drop the port count. The call is protected
> +		 * by the port mutex
> +		 */
>  		port->serial->type->close(tty, port, filp);
>  
> -	if (port->port.count == (port->console? 1 : 0)) {
> +	if (port->port.count == (port->console ? 2 : 1)) {

Why are you testing for 2 here?

confused,

greg k-h

  reply	other threads:[~2008-11-04 17:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04 15:29 [PATCH] tty: Fix close races in USB serial Alan Cox
2008-11-04 17:11 ` Greg KH [this message]
2008-11-04 17:37   ` Alan Cox
2008-11-04 17:55     ` Greg KH

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=20081104171128.GB630@kroah.com \
    --to=greg@kroah.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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