• Alan Stern's avatar
    USB: serial: fix lifetime and locking problems · 2d93148a
    Alan Stern authored
    This patch (as1229) fixes a few lifetime and locking problems in the
    usb-serial driver.  The main symptom is that an invalid kevent is
    created when the serial device is unplugged while a connection is
    active.
    
    	Ports should be unregistered when device is disconnected,
    	not when the parent usb_serial structure is deallocated.
    
    	Each open file should hold a reference to the corresponding
    	port structure, and the reference should be released when
    	the file is closed.
    
    	serial->disc_mutex should be acquired in serial_open(), to
    	resolve the classic race between open and disconnect.
    
    	serial_close() doesn't need to hold both serial->disc_mutex
    	and port->mutex at the same time.
    
    	Release the subdriver's module reference only after releasing
    	all the other references, in case one of the release routines
    	needs to invoke some code in the subdriver module.
    
    	Replace a call to flush_scheduled_work() (which is prone to
    	deadlocks) with cancel_work_sync().  Also, add a call to
    	cancel_work_sync() in the disconnect routine.
    
    	Reduce the scope of serial->disc_mutex in serial_disconnect().
    	The only place it really needs to protect is where the
    	"disconnected" flag is set.
    
    This fixes the bug reported in
    
    	http://bugs.freedesktop.org/show_bug.cgi?id=20703Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
    Tested-by: default avatarDan Williams <dcbw@redhat.com>
    Tested-by: default avatarMing Lei <tom.leiming@gmail.com>
    Reviewed-by: default avatarOliver Neukum <oliver@neukum.org>
    Acked-by: default avatarAlan Cox <alan@linux.intel.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
    
    2d93148a
usb-serial.c 35.1 KB