From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <greg@kroah.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
linuxppc-dev@ozlabs.org, Alan Stern <stern@rowland.harvard.edu>,
Li Yang <leoli@freescale.com>, Timur Tabi <timur@freescale.com>
Subject: [PATCH -mm 3/3] USB: FHCI: Fix memory leaks in fhci_mem_{init,free}
Date: Wed, 24 Dec 2008 22:13:42 +0300 [thread overview]
Message-ID: <20081224191342.GC21815@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <20081223210322.GA2802@oksana.dev.rtsoft.ru>
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 <avorontsov@ru.mvista.com>
---
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 */
--
1.5.6.5
WARNING: multiple messages have this Message-ID (diff)
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <greg@kroah.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
David Brownell <dbrownell@users.sourceforge.net>,
Timur Tabi <timur@freescale.com>, Li Yang <leoli@freescale.com>,
linux-usb@vger.kernel.org, linuxppc-dev@ozlabs.org,
linux-kernel@vger.kernel.org
Subject: [PATCH -mm 3/3] USB: FHCI: Fix memory leaks in fhci_mem_{init,free}
Date: Wed, 24 Dec 2008 22:13:42 +0300 [thread overview]
Message-ID: <20081224191342.GC21815@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <20081223210322.GA2802@oksana.dev.rtsoft.ru>
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 <avorontsov@ru.mvista.com>
---
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 */
--
1.5.6.5
next prev parent reply other threads:[~2008-12-24 19:13 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-23 21:03 [PATCH] USB: Driver for Freescale QUICC Engine USB Host Controller Anton Vorontsov
2008-12-23 21:03 ` Anton Vorontsov
2008-12-23 21:28 ` Andrew Morton
2008-12-23 21:28 ` Andrew Morton
2008-12-24 19:11 ` Anton Vorontsov
2008-12-24 19:11 ` Anton Vorontsov
2008-12-24 2:45 ` Alan Stern
2008-12-24 2:45 ` Alan Stern
2008-12-24 19:11 ` Anton Vorontsov
2008-12-24 19:11 ` Anton Vorontsov
2008-12-24 19:13 ` [PATCH -mm 1/3] USB: FHCI: Driver should be responsible for managing endpoint queues Anton Vorontsov
2008-12-24 19:13 ` Anton Vorontsov
2008-12-24 19:59 ` Greg KH
2008-12-24 19:59 ` Greg KH
2008-12-24 20:08 ` Anton Vorontsov
2008-12-24 20:08 ` Anton Vorontsov
2008-12-24 20:18 ` Andrew Morton
2008-12-24 20:18 ` Andrew Morton
2008-12-24 20:53 ` [PATCH v2] USB: Driver for Freescale QUICC Engine USB Host Controller Anton Vorontsov
2008-12-24 20:53 ` Anton Vorontsov
2008-12-24 20:58 ` [PATCH -mm 1/3] USB: FHCI: Driver should be responsible for managing endpoint queues Greg KH
2008-12-24 20:58 ` Greg KH
2008-12-24 21:07 ` Anton Vorontsov
2008-12-24 21:07 ` Anton Vorontsov
2008-12-24 22:54 ` Alan Stern
2008-12-24 22:54 ` Alan Stern
2008-12-24 19:13 ` [PATCH -mm 2/3] USB: FHCI: Fix namespace pollution Anton Vorontsov
2008-12-24 19:13 ` Anton Vorontsov
2008-12-24 19:13 ` Anton Vorontsov [this message]
2008-12-24 19:13 ` [PATCH -mm 3/3] USB: FHCI: Fix memory leaks in fhci_mem_{init,free} Anton Vorontsov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081224191342.GC21815@oksana.dev.rtsoft.ru \
--to=avorontsov@ru.mvista.com \
--cc=akpm@linux-foundation.org \
--cc=dbrownell@users.sourceforge.net \
--cc=greg@kroah.com \
--cc=leoli@freescale.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=stern@rowland.harvard.edu \
--cc=timur@freescale.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.