From patchwork Wed Dec 24 19:13:42 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 15535 X-Patchwork-Delegate: galak@kernel.crashing.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 5C8D8DDF17 for ; Thu, 25 Dec 2008 06:18:09 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: from buildserver.ru.mvista.com (unknown [85.21.88.6]) by ozlabs.org (Postfix) with ESMTP id 79BABDDF05 for ; Thu, 25 Dec 2008 06:13:43 +1100 (EST) Received: from localhost (unknown [10.150.0.9]) by buildserver.ru.mvista.com (Postfix) with ESMTP id 53A2C881A; Thu, 25 Dec 2008 00:13:43 +0400 (SAMT) Date: Wed, 24 Dec 2008 22:13:42 +0300 From: Anton Vorontsov To: Andrew Morton , Greg Kroah-Hartman Subject: [PATCH -mm 3/3] USB: FHCI: Fix memory leaks in fhci_mem_{init, free} Message-ID: <20081224191342.GC21815@oksana.dev.rtsoft.ru> References: <20081223210322.GA2802@oksana.dev.rtsoft.ru> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20081223210322.GA2802@oksana.dev.rtsoft.ru> User-Agent: Mutt/1.5.18 (2008-05-17) Cc: David Brownell , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, Alan Stern , Li Yang , Timur Tabi X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org This patch fixes few memory leaks. Particulary: - On errors fhci_mem_init() leaks fhci->hc_list; - fhci_mem_free() doesn't free the allocated eds/tds. Signed-off-by: Anton Vorontsov --- drivers/usb/host/fhci-hcd.c | 57 ++++++++++++++++++++++-------------------- 1 files changed, 30 insertions(+), 27 deletions(-) diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c index 269af3c..ba622cc 100644 --- a/drivers/usb/host/fhci-hcd.c +++ b/drivers/usb/host/fhci-hcd.c @@ -167,27 +167,35 @@ int fhci_ioports_check_bus_state(struct fhci_hcd *fhci) static void fhci_mem_free(struct fhci_hcd *fhci) { - struct list_head *lh; - struct list_head *next_lh; + struct ed *ed; + struct ed *next_ed; + struct td *td; + struct td *next_td; - list_for_each_safe(lh, next_lh, &fhci->empty_eds) - list_del(lh); + list_for_each_entry_safe(ed, next_ed, &fhci->empty_eds, node) { + list_del(&ed->node); + kfree(ed); + } - list_for_each_safe(lh, next_lh, &fhci->empty_tds) - list_del(lh); + list_for_each_entry_safe(td, next_td, &fhci->empty_tds, node) { + list_del(&td->node); + kfree(td); + } kfree(fhci->vroot_hub); + fhci->vroot_hub = NULL; + kfree(fhci->hc_list); + fhci->hc_list = NULL; } static int fhci_mem_init(struct fhci_hcd *fhci) { int i; - int error = 0; fhci->hc_list = kzalloc(sizeof(*fhci->hc_list), GFP_KERNEL); if (!fhci->hc_list) - return -ENOMEM; + goto err; INIT_LIST_HEAD(&fhci->hc_list->ctrl_list); INIT_LIST_HEAD(&fhci->hc_list->bulk_list); @@ -197,7 +205,7 @@ static int fhci_mem_init(struct fhci_hcd *fhci) fhci->vroot_hub = kzalloc(sizeof(*fhci->vroot_hub), GFP_KERNEL); if (!fhci->vroot_hub) - return -ENOMEM; + goto err; INIT_LIST_HEAD(&fhci->empty_eds); INIT_LIST_HEAD(&fhci->empty_tds); @@ -207,32 +215,27 @@ static int fhci_mem_init(struct fhci_hcd *fhci) fhci->process_done_task = &fhci_tasklet; for (i = 0; i < MAX_TDS; i++) { - struct td *td = kmalloc(sizeof(*td), GFP_KERNEL); + struct td *td; - if (!td) { - error = 1; - break; - } + td = kmalloc(sizeof(*td), GFP_KERNEL); + if (!td) + goto err; fhci_recycle_empty_td(fhci, td); } for (i = 0; i < MAX_EDS; i++) { - struct ed *ed = kmalloc(sizeof(*ed), GFP_KERNEL); + struct ed *ed; - if (!ed) { - error = 1; - break; - } + ed = kmalloc(sizeof(*ed), GFP_KERNEL); + if (!ed) + goto err; fhci_recycle_empty_ed(fhci, ed); } - if (error) { - fhci_mem_free(fhci); - return -ENOMEM; - } - fhci->active_urbs = 0; - - return error; + return 0; +err: + fhci_mem_free(fhci); + return -ENOMEM; } /* destroy the fhci_usb structure */