USB: serial: upd78f0730: fix NULL-deref on hangup
Subsystems (3)
Johan Hovold
maintainerPATCH 1/1 USB: serial: upd78f0730: fix NULL-deref on hangup
The port tty pointer is cleared on hangup before deasserting the modem control signals and should not be used in the dtr_rts() callback.
Factor out a new upd78f0730_port_tiocmset() helper that can be used in upd78f0730_dtr_rts() to avoid dereferencing a NULL-pointer on hangup (e.g. on disconnect).
This issue was flagged by an LLM.
--- drivers/usb/serial/upd78f0730.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/usb/serial/upd78f0730.c +9 -4
@@ -201,10 +201,9 @@ static int upd78f0730_tiocmget(struct tty_struct *tty)return res; } -static int upd78f0730_tiocmset (struct tty_struct *tty, +static int upd78f0730_port_tiocmset (struct usb_serial_port *port,unsigned int set,unsigned int clear) { -struct usb_serial_port *port = tty->driver_data;struct upd78f0730_port_private *private;struct upd78f0730_set_dtr_rts request;struct device *dev = &port->dev;
@@ -238,6 +237,13 @@ static int upd78f0730_tiocmset(struct tty_struct *tty,return res; } +static int upd78f0730_tiocmset (struct tty_struct *tty,unsigned int set,unsigned int clear) +{ +struct usb_serial_port *port = tty->driver_data; + +return upd78f0730_port_tiocmset (port, set, clear); +} +static int upd78f0730_break_ctl (struct tty_struct *tty,int break_state) {struct upd78f0730_port_private *private;
@@ -267,7 +273,6 @@ static int upd78f0730_break_ctl(struct tty_struct *tty, int break_state)static void upd78f0730_dtr_rts (struct usb_serial_port *port,int on) { -struct tty_struct *tty = port->port.tty;unsigned int set =0 ;unsigned int clear =0 ;
@@ -276,7 +281,7 @@ static void upd78f0730_dtr_rts(struct usb_serial_port *port, int on)else clear =TIOCM_DTR |TIOCM_RTS ; -upd78f0730_tiocmset (tty, set, clear); +upd78f0730_port_tiocmset (port, set, clear); }static speed_t upd78f0730_get_baud_rate (struct tty_struct *tty)
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 7 lines
The port tty pointer is cleared on hangup before deasserting the modem control signals and should not be used in the
dtr_rts()callback.Factor out a new
upd78f0730_port_tiocmset()helper that can be used inupd78f0730_dtr_rts()to avoid dereferencing a NULL-pointer on hangup (e.g. on disconnect).
Quoted 7 lines
This issue was flagged by an LLM.
Fixes ea534e0b4047 ("USB: serial: add uPD78F0730 USB to Serial Adaptor Driver")Cc [email protected] # 4.11Cc Maksim Salau <[email protected]>Assisted-by LLMSigned-off-by Johan Hovold <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1