USB: serial/keyspan_pda, fix potential tty NULL dereferences
Make sure that we check the return value of tty_port_tty_get. Sometimes it may return NULL and we later dereference that. There are several places to check. For easier handling, tty_port_tty_get is moved directly to the palce where needed in keyspan_pda_rx_interrupt. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
7adc14b14b
commit
f7d7aedfcd
|
@ -173,7 +173,8 @@ static void keyspan_pda_wakeup_write(struct work_struct *work)
|
||||||
container_of(work, struct keyspan_pda_private, wakeup_work);
|
container_of(work, struct keyspan_pda_private, wakeup_work);
|
||||||
struct usb_serial_port *port = priv->port;
|
struct usb_serial_port *port = priv->port;
|
||||||
struct tty_struct *tty = tty_port_tty_get(&port->port);
|
struct tty_struct *tty = tty_port_tty_get(&port->port);
|
||||||
tty_wakeup(tty);
|
if (tty)
|
||||||
|
tty_wakeup(tty);
|
||||||
tty_kref_put(tty);
|
tty_kref_put(tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
|
||||||
static void keyspan_pda_rx_interrupt(struct urb *urb)
|
static void keyspan_pda_rx_interrupt(struct urb *urb)
|
||||||
{
|
{
|
||||||
struct usb_serial_port *port = urb->context;
|
struct usb_serial_port *port = urb->context;
|
||||||
struct tty_struct *tty = tty_port_tty_get(&port->port);
|
struct tty_struct *tty;
|
||||||
unsigned char *data = urb->transfer_buffer;
|
unsigned char *data = urb->transfer_buffer;
|
||||||
int retval;
|
int retval;
|
||||||
int status = urb->status;
|
int status = urb->status;
|
||||||
|
@ -223,7 +224,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
|
||||||
/* this urb is terminated, clean up */
|
/* this urb is terminated, clean up */
|
||||||
dbg("%s - urb shutting down with status: %d",
|
dbg("%s - urb shutting down with status: %d",
|
||||||
__func__, status);
|
__func__, status);
|
||||||
goto out;
|
return;
|
||||||
default:
|
default:
|
||||||
dbg("%s - nonzero urb status received: %d",
|
dbg("%s - nonzero urb status received: %d",
|
||||||
__func__, status);
|
__func__, status);
|
||||||
|
@ -233,12 +234,14 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
|
||||||
/* see if the message is data or a status interrupt */
|
/* see if the message is data or a status interrupt */
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 0:
|
case 0:
|
||||||
/* rest of message is rx data */
|
tty = tty_port_tty_get(&port->port);
|
||||||
if (urb->actual_length) {
|
/* rest of message is rx data */
|
||||||
|
if (tty && urb->actual_length) {
|
||||||
tty_insert_flip_string(tty, data + 1,
|
tty_insert_flip_string(tty, data + 1,
|
||||||
urb->actual_length - 1);
|
urb->actual_length - 1);
|
||||||
tty_flip_buffer_push(tty);
|
tty_flip_buffer_push(tty);
|
||||||
}
|
}
|
||||||
|
tty_kref_put(tty);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
/* status interrupt */
|
/* status interrupt */
|
||||||
|
@ -265,8 +268,6 @@ exit:
|
||||||
dev_err(&port->dev,
|
dev_err(&port->dev,
|
||||||
"%s - usb_submit_urb failed with result %d",
|
"%s - usb_submit_urb failed with result %d",
|
||||||
__func__, retval);
|
__func__, retval);
|
||||||
out:
|
|
||||||
tty_kref_put(tty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue