From: Will Newton <will.newton@imgtec.com>
To: linux-kernel@vger.kernel.org
Cc: linux-usb@vger.kernel.org, leoli@freescale.com,
tanya.jiang@freescale.com, gregkh@suse.de,
Will Newton <will.newton@gmail.com>
Subject: [PATCH 11/11] fsl_usb2_udc: Fix oops on probe failure.
Date: Tue, 15 Jul 2008 16:24:50 +0100 [thread overview]
Message-ID: <1216135490-21656-12-git-send-email-will.newton@imgtec.com> (raw)
In-Reply-To: <1216135490-21656-11-git-send-email-will.newton@imgtec.com>
From: Will Newton <will.newton@gmail.com>
In some circumstances when fsl_udc_probe fails udc_controller is freed but
the pointer remains non-NULL. fsl_udc_remove will then try and teardown
the partly initialized and freed controller structure resulting in an oops.
This patch ensures udc_controller is either NULL or fully initialized after
fsl_udc_probe.
Signed-off-by: Will Newton <will.newton@gmail.com>
---
drivers/usb/gadget/fsl_usb2_udc.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index 15b7cea..f3bfe97 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -2244,21 +2244,21 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
- kfree(udc_controller);
- return -ENXIO;
+ ret = -ENXIO;
+ goto err_kfree;
}
if (!request_mem_region(res->start, res->end - res->start + 1,
driver_name)) {
ERR("request mem region for %s failed\n", pdev->name);
- kfree(udc_controller);
- return -EBUSY;
+ ret = -EBUSY;
+ goto err_kfree;
}
dr_regs = ioremap(res->start, res->end - res->start + 1);
if (!dr_regs) {
ret = -ENOMEM;
- goto err1;
+ goto err_release_mem_region;
}
usb_sys_regs = (struct usb_sys_interface *)
@@ -2269,7 +2269,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
if (!(dccparams & DCCPARAMS_DC)) {
ERR("This SOC doesn't support device role\n");
ret = -ENODEV;
- goto err2;
+ goto err_iounmap;
}
/* Get max device endpoints */
/* DEN is bidirectional ep number, max_ep doubles the number */
@@ -2278,7 +2278,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
udc_controller->irq = platform_get_irq(pdev, 0);
if (!udc_controller->irq) {
ret = -ENODEV;
- goto err2;
+ goto err_iounmap;
}
ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED,
@@ -2286,14 +2286,14 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
if (ret != 0) {
ERR("cannot request irq %d err %d\n",
udc_controller->irq, ret);
- goto err2;
+ goto err_iounmap;
}
/* Initialize the udc structure including QH member and other member */
if (struct_udc_setup(udc_controller, pdev)) {
ERR("Can't initialize udc data structure\n");
ret = -ENOMEM;
- goto err3;
+ goto err_free_irq;
}
/* initialize usb hw reg except for regs for EP,
@@ -2314,7 +2314,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
udc_controller->gadget.dev.parent = &pdev->dev;
ret = device_register(&udc_controller->gadget.dev);
if (ret < 0)
- goto err3;
+ goto err_free_irq;
/* setup QH and epctrl for ep0 */
ep0_setup(udc_controller);
@@ -2344,20 +2344,22 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
DTD_ALIGNMENT, UDC_DMA_BOUNDARY);
if (udc_controller->td_pool == NULL) {
ret = -ENOMEM;
- goto err4;
+ goto err_unregister;
}
create_proc_file();
return 0;
-err4:
+err_unregister:
device_unregister(&udc_controller->gadget.dev);
-err3:
+err_free_irq:
free_irq(udc_controller->irq, udc_controller);
-err2:
+err_iounmap:
iounmap(dr_regs);
-err1:
+err_release_mem_region:
release_mem_region(res->start, res->end - res->start + 1);
+err_kfree:
kfree(udc_controller);
+ udc_controller = NULL;
return ret;
}
--
1.5.5.2
next prev parent reply other threads:[~2008-07-15 15:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-15 15:24 [PATCH 00/11] fsl_usb2_udc: A number of bug fixes and cleanups Will Newton
2008-07-15 15:24 ` [PATCH 01/11] fsl_usb2_udc: Make dr_ep_setup function static Will Newton
2008-07-15 15:24 ` [PATCH 02/11] fsl_usb2_udc: Remove check for udc == NULL in dr_controller_setup Will Newton
2008-07-15 15:24 ` [PATCH 03/11] fsl_usb2_udc: Fix some sparse warnings and remove redundant code Will Newton
2008-07-15 15:24 ` [PATCH 04/11] fsl_usb2_udc: Clean up whitespace in errors and warnings Will Newton
2008-07-15 15:24 ` [PATCH 05/11] fsl_usb2_udc: Clean up whitespace in /proc debugging output Will Newton
2008-07-15 15:24 ` [PATCH 06/11] fsl_usb2_udc: Initialize spinlock earlier Will Newton
2008-07-15 15:24 ` [PATCH 07/11] fsl_usb2_udc: Rename the arguments of the fsl_writel macro Will Newton
2008-07-15 15:24 ` [PATCH 08/11] fsl_usb2_udc: Uninline udc_reset_ep_queue Will Newton
2008-07-15 15:24 ` [PATCH 09/11] fsl_usb2_udc: Make fsl_queue_td return type void Will Newton
2008-07-15 15:24 ` [PATCH 10/11] fsl_usb2_udc: Add a wmb before priming endpoint Will Newton
2008-07-15 15:24 ` Will Newton [this message]
2008-07-17 9:43 ` [PATCH 00/11] fsl_usb2_udc: A number of bug fixes and cleanups Li Yang
2008-07-17 9:47 ` Will Newton
2008-08-08 10:13 ` Will Newton
2008-08-12 11:27 ` Li Yang
2008-08-12 14:39 Will Newton
2008-08-12 14:39 ` [PATCH 01/11] fsl_usb2_udc: Make dr_ep_setup function static Will Newton
2008-08-12 14:39 ` [PATCH 02/11] fsl_usb2_udc: Remove check for udc == NULL in dr_controller_setup Will Newton
2008-08-12 14:39 ` [PATCH 03/11] fsl_usb2_udc: Fix some sparse warnings and remove redundant code Will Newton
2008-08-12 14:39 ` [PATCH 04/11] fsl_usb2_udc: Clean up whitespace in errors and warnings Will Newton
2008-08-12 14:39 ` [PATCH 05/11] fsl_usb2_udc: Clean up whitespace in /proc debugging output Will Newton
2008-08-12 14:39 ` [PATCH 06/11] fsl_usb2_udc: Initialize spinlock earlier Will Newton
2008-08-12 14:39 ` [PATCH 07/11] fsl_usb2_udc: Rename the arguments of the fsl_writel macro Will Newton
2008-08-12 14:39 ` [PATCH 08/11] fsl_usb2_udc: Uninline udc_reset_ep_queue Will Newton
2008-08-12 14:39 ` [PATCH 09/11] fsl_usb2_udc: Make fsl_queue_td return type void Will Newton
2008-08-12 14:39 ` [PATCH 10/11] fsl_usb2_udc: Add a wmb before priming endpoint Will Newton
2008-08-12 14:39 ` [PATCH 11/11] fsl_usb2_udc: Fix oops on probe failure Will Newton
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=1216135490-21656-12-git-send-email-will.newton@imgtec.com \
--to=will.newton@imgtec.com \
--cc=gregkh@suse.de \
--cc=leoli@freescale.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=tanya.jiang@freescale.com \
--cc=will.newton@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®