lkml.org 
[lkml]   [2013]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [Fwd: [PATCH v2 0/4] TTY: port hangup and close fixes]
From
Date
On Tue, 2013-03-05 at 23:10 +0100, Jiri Slaby wrote:
> On 03/05/2013 11:02 PM, Peter Hurley wrote:
> > On Tue, 2013-03-05 at 22:56 +0100, Jiri Slaby wrote:
> >> On 03/05/2013 06:06 PM, Peter Hurley wrote:
> >>>>> @@ -225,15 +232,13 @@ void tty_port_hangup(struct tty_port *port)
> >>>> spin_lock_irqsave(&port->lock, flags);
> >>>> port->count = 0;
> >>>> port->flags &= ~ASYNC_NORMAL_ACTIVE;
> >>>> - if (port->tty) {
> >>>> + if (port->tty)
> >>>> set_bit(TTY_IO_ERROR, &port->tty->flags);
> >>>> - tty_kref_put(port->tty);
> >>>> - }
> >>>> - port->tty = NULL;
> >>>> spin_unlock_irqrestore(&port->lock, flags);
> >>>>> + tty_port_shutdown(port, port->tty);
> >>>>
> >>>> What prevents port->tty to be NULL here already?
> >>>
> >>> Nothing. That's why it's tested in tty_port_shutdown() above.
> >>
> >> I know :).
> >
> > Sorry :)
> >
> >> But the question is rather don't we want to pass the real
> >> refcounted port->tty (take a snapshot inside the lock) instead?
> >
> > I think that's why he moved the kref release to after the shutdown (via
> > tty_port_set_tty()) -- but I'm tired and maybe I'm missing something
> > here?
>
> port->tty can be changed right after the unlock.

Right. My bad. Thanks for catching this.

> So I'm thinking about
> something like this:
>
> if (port->tty)
> set_bit(TTY_IO_ERROR, &port->tty->flags);
> tty = port->tty; <=== take a snapshot
> spin_unlock_irqrestore(&port->lock, flags);
> tty_port_shutdown(port, tty); <=== use the snapshot
> set_tty_port(port, NULL); <=== put kref on that tty

Yeah, that's better.

Regards,
Peter Hurley



\
 
 \ /
  Last update: 2013-03-06 00:21    [W:0.059 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site