Commit 6ff428d6 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: mos7840: fix memory leak in open

commit 5f8a2e68 upstream.

Allocated urbs and buffers were never freed on errors in open.
Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Cc: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8dc18301
...@@ -923,20 +923,20 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -923,20 +923,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) {
dbg("Reading Spreg failed"); dbg("Reading Spreg failed");
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) {
dbg("writing Spreg failed"); dbg("writing Spreg failed");
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) {
dbg("writing Spreg failed"); dbg("writing Spreg failed");
return -1; goto err;
} }
/* End of block to be checked */ /* End of block to be checked */
...@@ -945,7 +945,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -945,7 +945,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
&Data); &Data);
if (status < 0) { if (status < 0) {
dbg("Reading Controlreg failed"); dbg("Reading Controlreg failed");
return -1; goto err;
} }
Data |= 0x08; /* Driver done bit */ Data |= 0x08; /* Driver done bit */
Data |= 0x20; /* rx_disable */ Data |= 0x20; /* rx_disable */
...@@ -953,7 +953,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -953,7 +953,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) {
dbg("writing Controlreg failed"); dbg("writing Controlreg failed");
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. */
...@@ -964,21 +964,21 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -964,21 +964,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) {
dbg("disabling interrupts failed"); dbg("disabling interrupts failed");
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) {
dbg("Writing FIFO_CONTROL_REGISTER failed"); dbg("Writing FIFO_CONTROL_REGISTER failed");
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) {
dbg("Writing FIFO_CONTROL_REGISTER failed"); dbg("Writing FIFO_CONTROL_REGISTER failed");
return -1; goto err;
} }
Data = 0x03; Data = 0x03;
...@@ -1134,7 +1134,15 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) ...@@ -1134,7 +1134,15 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
dbg ("%s leave", __func__); dbg ("%s leave", __func__);
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