Skip to contentSkip to conversation

usb: gadget: file_storage: Fix error path

PATCH In review Rahul Ruikar 3 participants 4 messages Oct 3, 2010 – Oct 4, 2010 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: file_storage: Fix error path

call put_device() when device_register() fails.

---
 drivers/usb/gadget/file_storage.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/usb/gadget/file_storage.c +1 -0
index a857b7a..2c94318 100644
@@ -3413,6 +3413,7 @@ static int __ref fsg_bind(struct usb_gadget *gadget)
 
 		if ((rc = device_register(&curlun->dev)) != 0) {
 			INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
+			put_device(&curlun->dev);
 			goto out;
 		}
 		if ((rc = device_create_file(&curlun->dev,
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 12 lines · Rahul Ruikar

call put_device() when device_register() fails.

---
 drivers/usb/gadget/file_storage.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/usb/gadget/file_storage.c +0 -0
index a857b7a..2c94318 100644

drivers/usb/gadget/file_storage.c static int __ref fsg_bind(struct usb_gadget *gadget) · line 3419

Quoted 7 lines
drivers/usb/gadget/file_storage.c +1 -0
@@ -3413,6 +3413,7 @@ static int __ref fsg_bind(struct usb_gadget *gadget)
 
 		if ((rc = device_register(&curlun->dev)) != 0) {
 			INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
+			put_device(&curlun->dev);
 			goto out;
 		}
 		if ((rc = device_create_file(&curlun->dev,

I'm afraid this is wrong as well. You need to move the "kref_get(&fsg->ref);" line up before the device_register call; otherwise the lun_release routine will do an unbalanced kref_put. In fact there is a similar bug in the original code, in the failure path for the device_create_file calls.

This seems to be a common pattern of mistakes in your patches. Maybe you should go through and check all of them; make sure that everything the release routine _undoes_ is certain to be _done_ before the device_register call.

Alan Stern

Acked-by Michal Nazarewicz on v1 1/1
#2 lore raw
In reply to Rahul Ruikar
Quoted 1 line · Rahul Ruikar

call put_device() when device_register() fails.

Capital letter at the beginning of sentence please. ;)

Quoted 2 lines

(or even Reviewed? dunno if that makes sense for such a trivial patch.)

Quoted 9 lines
---
 drivers/usb/gadget/file_storage.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/usb/gadget/file_storage.c +0 -0
index a857b7a..2c94318 100644

drivers/usb/gadget/file_storage.c static int __ref fsg_bind(struct usb_gadget *gadget) · line 3418

Quoted 6 lines
drivers/usb/gadget/file_storage.c +1 -0
@@ -3413,6 +3413,7 @@ static int __ref fsg_bind(struct usb_gadget *gadget)
 		if ((rc = device_register(&curlun->dev)) != 0) {
 			INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
+			put_device(&curlun->dev);
 			goto out;
 		}
 		if ((rc = device_create_file(&curlun->dev,

The same problem is with f_mass_storage.c. I'd be nice if you'd resubmit your patch with the below included as well:

drivers/usb/gadget/f_mass_storage.c +1 -0
index 44e5ffe..0b86174 100644
@@ -2764,6 +2764,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
 		rc = device_register(&curlun->dev);
 		if (rc) {
 			INFO(common, "failed to register LUN%d: %d\n", i, rc);
+			put_device(&curlun->dev);
 			common->nluns = i;
 			goto error_release;
 		}

Thanks.

Signature · 4 lines
Best regards,                                        _     _
| Humble Liege of Serenely Enlightened Majesty of  o' \,=./ `o
| Computer Science,  Michał "mina86" Nazarewicz       (o o)
+----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--
#3 lore raw
Quoted 2 lines · Michał Nazarewicz

The same problem is with f_mass_storage.c. I'd be nice if you'd resubmit your patch with the below included as well:

I've noticed that you've send is as a separate file. Disregard this comment then (even though I still think the two might be squashed together).

Moreover, disregard my mail, as I was wrong acking. Alan is of course correct.

Signature · 4 lines
Best regards,                                        _     _
| Humble Liege of Serenely Enlightened Majesty of  o' \,=./ `o
| Computer Science,  Michał "mina86" Nazarewicz       (o o)
+----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--