All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] USB: gadget: file_storage: put_device() in error recovery
@ 2010-10-26 13:38 Michal Nazarewicz
  2010-10-26 13:38 ` [PATCH 2/7] USB: gadget: f_mass_storage: " Michal Nazarewicz
  2010-10-26 14:09 ` [PATCH 1/7] USB: gadget: file_storage: put_device() in error recovery Alan Stern
  0 siblings, 2 replies; 21+ messages in thread
From: Michal Nazarewicz @ 2010-10-26 13:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Michal Nazarewicz, Alan Stern

From: Michal Nazarewicz <mina86@mina86.com>

This commit fixes some issues with File-backed Storage Gadget
error recovery when registering LUN's devices.

First of all, when device_register() fails the device still
needs to be put.  However, because lun_release() decreases
fsg->ref reference counter the counter must be incremented
beforehand.

Second of all, after any of the device_create_file()s fails,
device_unregister() is called which in turn (indirectly) calls
lun_release() which decrements fsg->ref.  So, again, the
reference counter must be incremented beforehand.

Lastly, if the first or the second device_create_file()
succeeds, the files are never removed.  To fix it,
device_remove_file() needs to be called.  This is done by
simply marking LUN as registered prior to creating files so
that fsg_unbind() can handle removing files.

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Reported-by: Rahul Ruikar <rahul.ruikar@gmail.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
---
 drivers/usb/gadget/file_storage.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

Rahul sent an invalid fix for the missing put_device() problem some time
ago.  This is, I believe, a correct one.  It also fixes the problem with
device files not being removed (as described in commit message); not sure
if the latter is a big issue though.

Hope I'm not late for 37?

diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index d4fdf65..e0504a1 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3392,21 +3392,19 @@ static int __init fsg_bind(struct usb_gadget *gadget)
 		dev_set_name(&curlun->dev,"%s-lun%d",
 			     dev_name(&gadget->dev), i);
 
-		if ((rc = device_register(&curlun->dev)) != 0) {
+		kref_get(&fsg->ref);
+		rc = device_register(&curlun->dev);
+		if (rc) {
 			INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
-			goto out;
-		}
-		if ((rc = device_create_file(&curlun->dev,
-					&dev_attr_ro)) != 0 ||
-				(rc = device_create_file(&curlun->dev,
-					&dev_attr_nofua)) != 0 ||
-				(rc = device_create_file(&curlun->dev,
-					&dev_attr_file)) != 0) {
-			device_unregister(&curlun->dev);
+			put_device(&curlun->dev);
 			goto out;
 		}
 		curlun->registered = 1;
-		kref_get(&fsg->ref);
+
+		if ((rc = device_create_file(&curlun->dev, &dev_attr_ro))  ||
+		    (rc = device_create_file(&curlun->dev, &dev_attr_nofua)) ||
+		    (rc = device_create_file(&curlun->dev, &dev_attr_file)))
+			goto out;
 
 		if (mod_data.file[i] && *mod_data.file[i]) {
 			if ((rc = fsg_lun_open(curlun,
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2010-11-12 13:31 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-26 13:38 [PATCH 1/7] USB: gadget: file_storage: put_device() in error recovery Michal Nazarewicz
2010-10-26 13:38 ` [PATCH 2/7] USB: gadget: f_mass_storage: " Michal Nazarewicz
2010-10-26 13:38   ` [PATCH 3/7] USB: gadget: f_mass_storage: use ?: instead of a macro Michal Nazarewicz
2010-10-26 13:38     ` [PATCH 4/7] USB: gadget: f_mass_storage: drop START_TRANSFER() macro Michal Nazarewicz
2010-10-26 13:38       ` [PATCH 5/7] USB: gadget: f_mass_storage: remove needless complete() Michal Nazarewicz
2010-10-26 13:38         ` [PATCH 6/7] USB: gadget: f_mass_storage: code style clean ups Michal Nazarewicz
2010-10-26 13:38           ` [PATCH 7/7] usb: gadget: FunctionFS: fix typos and coding styles Michal Nazarewicz
2010-10-26 14:09 ` [PATCH 1/7] USB: gadget: file_storage: put_device() in error recovery Alan Stern
2010-10-26 15:03   ` Michał Nazarewicz
2010-10-26 15:14     ` Alan Stern
2010-10-26 15:26       ` Michał Nazarewicz
2010-10-28 15:31   ` [PATCHv2 " Michal Nazarewicz
2010-10-28 15:31     ` [PATCHv2 2/7] USB: gadget: f_mass_storage: " Michal Nazarewicz
2010-10-28 15:31     ` [PATCHv2 3/7] USB: gadget: f_mass_storage: use ?: instead of a macro Michal Nazarewicz
2010-10-28 15:31     ` [PATCHv2 4/7] USB: gadget: f_mass_storage: drop START_TRANSFER() macro Michal Nazarewicz
2010-10-28 15:31     ` [PATCHv2 5/7] USB: gadget: f_mass_storage: remove needless complete() Michal Nazarewicz
2010-10-28 15:31     ` [PATCHv2 6/7] USB: gadget: f_mass_storage: code style clean ups Michal Nazarewicz
2010-10-28 15:31     ` [PATCHv2 7/7] USB: gadget: FunctionFS: fix typos and coding styles Michal Nazarewicz
2010-11-11 13:59       ` Greg KH
2010-11-12 13:29         ` [PATCH 1/2] usb: gadget: FunctionFS: fix typos and coding style Michal Nazarewicz
2010-11-12 13:29           ` [PATCH 2/2] usb: gadget: f_fs: remove custom printk() wrappers Michal Nazarewicz

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.