[patch 0/1] fix async usb removal

Samuel Thibault samuel.thibault at ens-lyon.org
Wed Aug 9 14:00:06 EDT 2017


Okash Khawaja, on mar. 08 août 2017 06:51:58 +0100, wrote:
> On Mon, Aug 07, 2017 at 11:18:44PM +0200, Samuel Thibault wrote:
> > >  static void spk_ttyio_send_xchar(char ch)
> > >  {
> > > +	if (check_tty(speakup_tty))
> > > +		return;
> > > +
> > >  	speakup_tty->ops->send_xchar(speakup_tty, ch);
> > >  }
> > 
> > This is still unsafe: the unplug might come just between testing for
> > speakup_tty becoming NULL and using it.
> 
> I thought about that but couldn't find a way to overcome it in a
> foolproof way. Here's my reasoning. Since the unplugging of usb is
> asynchronous to us calling methods on speakup_tty, speakup_tty can
> become null in a separate thread.

Then more synchronization is needed: spk_ttyio_ldisc_close needs to
wait for methods to be finished calling.  It would probably be enough
to introduce a mere mutex that would be taken around the uses of
speakup_tty, and in spk_ttyio_ldisc_close, so that it both waits for
uses of speakup_tty, and delay others from happening.

Samuel


More information about the Speakup mailing list