From: Rahul Ruikar <rahul.ruikar@gmail.com>
To: David Brownell <dbrownell@users.sourceforge.net>,
Greg Kroah-Hartman <gregkh@suse.de>,
Joe Perches <joe@perches.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Rahul Ruikar <rahul.ruikar@gmail.com>
Subject: [PATCH] usb: gadget: langwell_udc: Fix error path
Date: Thu, 7 Oct 2010 09:22:06 +0530 [thread overview]
Message-ID: <1286423526-2777-1-git-send-email-rahul.ruikar@gmail.com> (raw)
Fix for following cases
- Call device_unregister() only when device_register() succeeds.
- Call put_device() when device_register() fails.
- Call device_remove_file() only when device_create_file() succeeds.
Signed-off-by: Rahul Ruikar <rahul.ruikar@gmail.com>
---
drivers/usb/gadget/langwell_udc.c | 14 +++++++++++---
drivers/usb/gadget/langwell_udc.h | 4 +++-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index c2d2a20..56e216e 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -2952,8 +2952,11 @@ static void langwell_udc_remove(struct pci_dev *pdev)
INFO(dev, "unbind\n");
DBG(dev, "<--- %s()\n", __func__);
- device_unregister(&dev->gadget.dev);
- device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
+ if (dev->reg_status)
+ device_unregister(&dev->gadget.dev);
+
+ if (dev->file_created)
+ device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
#ifndef OTG_TRANSCEIVER
pci_set_drvdata(pdev, NULL);
@@ -3190,13 +3193,18 @@ static int langwell_udc_probe(struct pci_dev *pdev,
the_controller = dev;
retval = device_register(&dev->gadget.dev);
- if (retval)
+ if (retval) {
+ put_device(&dev->gadget.dev);
goto error;
+ }
+ dev->reg_status = 1;
retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc);
if (retval)
goto error;
+ dev->file_created = 1;
+
VDBG(dev, "<--- %s()\n", __func__);
return 0;
diff --git a/drivers/usb/gadget/langwell_udc.h b/drivers/usb/gadget/langwell_udc.h
index 9719934..da40671 100644
--- a/drivers/usb/gadget/langwell_udc.h
+++ b/drivers/usb/gadget/langwell_udc.h
@@ -199,7 +199,9 @@ struct langwell_udc {
vbus_active:1,
suspended:1,
stopped:1,
- lpm:1; /* LPM capability */
+ lpm:1, /* LPM capability */
+ reg_status:1,
+ file_created:1;
/* pci state used to access those endpoints */
struct pci_dev *pdev;
--
1.7.2.3
next reply other threads:[~2010-10-07 3:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-07 3:52 Rahul Ruikar [this message]
2010-10-07 3:54 ` Rahul Ruikar
2010-10-07 17:51 ` Greg KH
2010-10-07 18:19 ` Rahul Ruikar
2010-10-07 20:48 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2010-10-05 18:20 Rahul Ruikar
2010-10-05 19:17 ` Sergei Shtylyov
2010-10-06 2:34 ` Rahul Ruikar
2010-10-06 20:21 ` Greg KH
2010-10-07 3:55 ` Rahul Ruikar
2010-10-03 13:49 Rahul Ruikar
2010-10-04 10:44 ` Sergei Shtylyov
2010-10-04 10:52 ` Rahul Ruikar
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=1286423526-2777-1-git-send-email-rahul.ruikar@gmail.com \
--to=rahul.ruikar@gmail.com \
--cc=dbrownell@users.sourceforge.net \
--cc=gregkh@suse.de \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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
Powered by JetHome