Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935262AbaDJECe (ORCPT ); Thu, 10 Apr 2014 00:02:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:41144 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934851AbaDJDWa (ORCPT ); Wed, 9 Apr 2014 23:22:30 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold , Ben Hutchings , Yang Yingliang Subject: [PATCH 3.4 078/134] USB: mos7840: fix memory leak in open Date: Wed, 9 Apr 2014 20:23:14 -0700 Message-Id: <20140410032309.989897056@linuxfoundation.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <20140410032259.587501440@linuxfoundation.org> References: <20140410032259.587501440@linuxfoundation.org> User-Agent: quilt/0.60-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 5f8a2e68b679b41cc8e9b642f2f5aa45dd678641 upstream. Allocated urbs and buffers were never freed on errors in open. Signed-off-by: Johan Hovold [bwh: Backported to 3.2: adjust context] Signed-off-by: Ben Hutchings Cc: Yang Yingliang Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/mos7840.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -923,20 +923,20 @@ static int mos7840_open(struct tty_struc status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); if (status < 0) { dbg("Reading Spreg failed"); - return -1; + goto err; } Data |= 0x80; status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); if (status < 0) { dbg("writing Spreg failed"); - return -1; + goto err; } Data &= ~0x80; status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, Data); if (status < 0) { dbg("writing Spreg failed"); - return -1; + goto err; } /* End of block to be checked */ @@ -945,7 +945,7 @@ static int mos7840_open(struct tty_struc &Data); if (status < 0) { dbg("Reading Controlreg failed"); - return -1; + goto err; } Data |= 0x08; /* Driver done bit */ Data |= 0x20; /* rx_disable */ @@ -953,7 +953,7 @@ static int mos7840_open(struct tty_struc mos7840_port->ControlRegOffset, Data); if (status < 0) { dbg("writing Controlreg failed"); - return -1; + goto err; } /* do register settings here */ /* Set all regs to the device default values. */ @@ -964,21 +964,21 @@ static int mos7840_open(struct tty_struc status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); if (status < 0) { dbg("disabling interrupts failed"); - return -1; + goto err; } /* Set FIFO_CONTROL_REGISTER to the default value */ Data = 0x00; status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); if (status < 0) { dbg("Writing FIFO_CONTROL_REGISTER failed"); - return -1; + goto err; } Data = 0xcf; status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); if (status < 0) { dbg("Writing FIFO_CONTROL_REGISTER failed"); - return -1; + goto err; } Data = 0x03; @@ -1134,7 +1134,15 @@ static int mos7840_open(struct tty_struc dbg ("%s leave", __func__); 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; } /***************************************************************************** -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/