mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: file_storage: Fix error path
@ 2010-10-03  4:55 Rahul Ruikar
  2010-10-03 15:59 ` Alan Stern
  2010-10-04  9:39 ` Michał Nazarewicz
  0 siblings, 2 replies; 4+ messages in thread
From: Rahul Ruikar @ 2010-10-03  4:55 UTC (permalink / raw)
  To: David Brownell, Greg Kroah-Hartman, Michal Nazarewicz,
	Christoph Hellwig, Alan Stern, Andrew Morton
  Cc: linux-usb, linux-kernel, Rahul Ruikar

call put_device() when device_register() fails.

Signed-off-by: Rahul Ruikar <rahul.ruikar@gmail.com>
---
 drivers/usb/gadget/file_storage.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a857b7a..2c94318 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -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,
-- 
1.7.2.3


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

* Re: [PATCH] usb: gadget: file_storage: Fix error path
  2010-10-03  4:55 [PATCH] usb: gadget: file_storage: Fix error path Rahul Ruikar
@ 2010-10-03 15:59 ` Alan Stern
  2010-10-04  9:39 ` Michał Nazarewicz
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Stern @ 2010-10-03 15:59 UTC (permalink / raw)
  To: Rahul Ruikar
  Cc: David Brownell, Greg Kroah-Hartman, Michal Nazarewicz,
	Christoph Hellwig, Andrew Morton, linux-usb, linux-kernel

On Sun, 3 Oct 2010, Rahul Ruikar wrote:

> call put_device() when device_register() fails.
> 
> Signed-off-by: Rahul Ruikar <rahul.ruikar@gmail.com>
> ---
>  drivers/usb/gadget/file_storage.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
> index a857b7a..2c94318 100644
> --- a/drivers/usb/gadget/file_storage.c
> +++ b/drivers/usb/gadget/file_storage.c
> @@ -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


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

* Re: [PATCH] usb: gadget: file_storage: Fix error path
  2010-10-03  4:55 [PATCH] usb: gadget: file_storage: Fix error path Rahul Ruikar
  2010-10-03 15:59 ` Alan Stern
@ 2010-10-04  9:39 ` Michał Nazarewicz
  2010-10-04 11:33   ` Michał Nazarewicz
  1 sibling, 1 reply; 4+ messages in thread
From: Michał Nazarewicz @ 2010-10-04  9:39 UTC (permalink / raw)
  To: David Brownell, Greg Kroah-Hartman, Christoph Hellwig,
	Alan Stern, Andrew Morton, Rahul Ruikar
  Cc: linux-usb, linux-kernel

On Sun, 03 Oct 2010 06:55:17 +0200, Rahul Ruikar <rahul.ruikar@gmail.com> wrote:
> call put_device() when device_register() fails.

Capital letter at the beginning of sentence please. ;)

>
> Signed-off-by: Rahul Ruikar <rahul.ruikar@gmail.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

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

> ---
>  drivers/usb/gadget/file_storage.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
> index a857b7a..2c94318 100644
> --- a/drivers/usb/gadget/file_storage.c
> +++ b/drivers/usb/gadget/file_storage.c
> @@ -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:

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 44e5ffe..0b86174 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -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.

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

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

* Re: [PATCH] usb: gadget: file_storage: Fix error path
  2010-10-04  9:39 ` Michał Nazarewicz
@ 2010-10-04 11:33   ` Michał Nazarewicz
  0 siblings, 0 replies; 4+ messages in thread
From: Michał Nazarewicz @ 2010-10-04 11:33 UTC (permalink / raw)
  To: David Brownell, Greg Kroah-Hartman, Christoph Hellwig,
	Alan Stern, Andrew Morton, Rahul Ruikar, Michał Nazarewicz
  Cc: linux-usb, linux-kernel

On Mon, 04 Oct 2010 11:39:51 +0200, Michał Nazarewicz <m.nazarewicz@samsung.com> wrote:
> 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.

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

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-03  4:55 [PATCH] usb: gadget: file_storage: Fix error path Rahul Ruikar
2010-10-03 15:59 ` Alan Stern
2010-10-04  9:39 ` Michał Nazarewicz
2010-10-04 11:33   ` Michał Nazarewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®