usb: gadget: file_storage: Fix error path
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
@@ -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
Quoted 12 lines · Rahul Ruikar
call
put_device()whendevice_register()fails.Signed-off-by Rahul Ruikar <[email protected]>--- drivers/usb/gadget/file_storage.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)drivers/usb/gadget/file_storage.c +0
-0
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
Quoted 1 line · Rahul Ruikar
call
put_device()whendevice_register()fails.
Capital letter at the beginning of sentence please. ;)
Quoted 2 lines
Signed-off-by Rahul Ruikar <[email protected]>
(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
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
@@ -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--
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--