Skip to content

Commit c529c37

Browse files
Kuen-Han Tsaigregkh
authored andcommitted
usb: gadget: u_serial: Fix race condition in TTY wakeup
A race condition occurs when gs_start_io() calls either gs_start_rx() or gs_start_tx(), as those functions briefly drop the port_lock for usb_ep_queue(). This allows gs_close() and gserial_disconnect() to clear port.tty and port_usb, respectively. Use the null-safe TTY Port helper function to wake up TTY. Example CPU1: CPU2: gserial_connect() // lock gs_close() // await lock gs_start_rx() // unlock usb_ep_queue() gs_close() // lock, reset port.tty and unlock gs_start_rx() // lock tty_wakeup() // NPE Fixes: 35f95fd ("TTY: usb/u_serial, use tty from tty_port") Cc: stable <[email protected]> Signed-off-by: Kuen-Han Tsai <[email protected]> Reviewed-by: Prashanth K <[email protected]> Link: https://lore.kernel.org/linux-usb/[email protected]/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f6c7bc4 commit c529c37

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/usb/gadget/function/u_serial.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ __acquires(&port->port_lock)
295295
break;
296296
}
297297

298-
if (do_tty_wake && port->port.tty)
299-
tty_wakeup(port->port.tty);
298+
if (do_tty_wake)
299+
tty_port_tty_wakeup(&port->port);
300300
return status;
301301
}
302302

@@ -574,7 +574,7 @@ static int gs_start_io(struct gs_port *port)
574574
gs_start_tx(port);
575575
/* Unblock any pending writes into our circular buffer, in case
576576
* we didn't in gs_start_tx() */
577-
tty_wakeup(port->port.tty);
577+
tty_port_tty_wakeup(&port->port);
578578
} else {
579579
/* Free reqs only if we are still connected */
580580
if (port->port_usb) {

0 commit comments

Comments
 (0)