Re: [PATCH] usb: gadget: langwell_udc: Fix error path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



updated patch with following changes.
- variable name changed
- comment updated.

Please find it attached here.

- Rahul Ruikar





On 6 October 2010 00:47, Sergei Shtylyov <sshtylyov@xxxxxxxxxx> wrote:
> Hello.
>
> Rahul Ruikar wrote:
>
>> Fix for following cases
>> - Call device_unregister() only when device_register() is success.
>
>   s/is success/succeeds/
>
>> - Call put_device() when device_register() fails.
>> - Call device_remove_file() only when device_create_file() is success.
>
>   s/is success/succeeds/
>
>> Signed-off-by: Rahul Ruikar <rahul.ruikar@xxxxxxxxx>
>
> [...]
>
>> diff --git a/drivers/usb/gadget/langwell_udc.h
>> b/drivers/usb/gadget/langwell_udc.h
>> index 9719934..b212a70 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_create:1;
>
>   I'd rather have called this 'file_created'.
>
>>        /* pci state used to access those endpoints */
>>        struct pci_dev          *pdev;
>
> WBR, Sergei
>
From d6a54bd6b050ffbe8ad5da0744a329d8c2aef190 Mon Sep 17 00:00:00 2001
From: Rahul Ruikar <rahul.ruikar@xxxxxxxxx>
Date: Tue, 5 Oct 2010 23:34:05 +0530
Subject: [PATCH] usb: gadget: langwell_udc: Fix error path

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@xxxxxxxxx>
---
 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


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux