Commit 5f8a2e68 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: mos7840: fix memory leak in open

Allocated urbs and buffers were never freed on errors in open.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 878c69aa
...@@ -905,20 +905,20 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -905,20 +905,20 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "Reading Spreg failed\n"); dev_dbg(&port->dev, "Reading Spreg failed\n");
return -1; goto err;
} }
Data |= 0x80; Data |= 0x80;
status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "writing Spreg failed\n"); dev_dbg(&port->dev, "writing Spreg failed\n");
return -1; goto err;
} }
Data &= ~0x80; Data &= ~0x80;
status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "writing Spreg failed\n"); dev_dbg(&port->dev, "writing Spreg failed\n");
return -1; goto err;
} }
/* End of block to be checked */ /* End of block to be checked */
...@@ -927,7 +927,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -927,7 +927,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
&Data); &Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "Reading Controlreg failed\n"); dev_dbg(&port->dev, "Reading Controlreg failed\n");
return -1; goto err;
} }
Data |= 0x08; /* Driver done bit */ Data |= 0x08; /* Driver done bit */
Data |= 0x20; /* rx_disable */ Data |= 0x20; /* rx_disable */
...@@ -935,7 +935,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -935,7 +935,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
mos7840_port->ControlRegOffset, Data); mos7840_port->ControlRegOffset, Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "writing Controlreg failed\n"); dev_dbg(&port->dev, "writing Controlreg failed\n");
return -1; goto err;
} }
/* do register settings here */ /* do register settings here */
/* Set all regs to the device default values. */ /* Set all regs to the device default values. */
...@@ -946,21 +946,21 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -946,21 +946,21 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "disabling interrupts failed\n"); dev_dbg(&port->dev, "disabling interrupts failed\n");
return -1; goto err;
} }
/* Set FIFO_CONTROL_REGISTER to the default value */ /* Set FIFO_CONTROL_REGISTER to the default value */
Data = 0x00; Data = 0x00;
status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n"); dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
return -1; goto err;
} }
Data = 0xcf; Data = 0xcf;
status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data);
if (status < 0) { if (status < 0) {
dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n"); dev_dbg(&port->dev, "Writing FIFO_CONTROL_REGISTER failed\n");
return -1; goto err;
} }
Data = 0x03; Data = 0x03;
...@@ -1103,6 +1103,15 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -1103,6 +1103,15 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
/* mos7840_change_port_settings(mos7840_port,old_termios); */ /* mos7840_change_port_settings(mos7840_port,old_termios); */
return 0; return 0;
err:
for (j = 0; j < NUM_URBS; ++j) {
urb = mos7840_port->write_urb_pool[j];
if (!urb)
continue;
kfree(urb->transfer_buffer);
usb_free_urb(urb);
}
return status;
} }
/***************************************************************************** /*****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment