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

From: Alan Stern
Date: Sun Oct 03 2010 - 11:59:55 EST


On Sun, 3 Oct 2010, Rahul Ruikar wrote:

> call put_device() when device_register() fails.
>
> Signed-off-by: Rahul Ruikar <rahul.ruikar@xxxxxxxxx>
> ---
> 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/