diff mbox series

usb: gadget: u_serial: Add null pointer check in gs_close

Message ID 20230904105455.13090-1-jiazi.li@transsion.com
State New
Headers show
Series usb: gadget: u_serial: Add null pointer check in gs_close | expand

Commit Message

Jiazi Li Sept. 4, 2023, 10:54 a.m. UTC
If kfifo_alloc return err in gs_open, tty->driver_data will not
be assigned a legal value.
This will result in a NULL pointer issue when calling gs_close in
the following error handling:
tty_open
    ->tty_release
        ->gs_close		
Add a null pointer check in gs_close to prevent this.

Signed-off-by: Jiazi.Li <jiazi.li@transsion.com>
---
 drivers/usb/gadget/function/u_serial.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index a92eb6d90976..9a04b34bbe8c 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -680,6 +680,9 @@  static void gs_close(struct tty_struct *tty, struct file *file)
 	struct gs_port *port = tty->driver_data;
 	struct gserial	*gser;
 
+	if (!port)
+		return;
+
 	spin_lock_irq(&port->port_lock);
 
 	if (port->port.count != 1) {