netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] p54usb: fix leaks at failure path in p54u_probe()
@ 2014-03-07 21:11 Alexey Khoroshilov
  2014-03-07 21:27 ` Christian Lamparter
  2014-03-08 22:44 ` Krishna Chaitanya
  0 siblings, 2 replies; 6+ messages in thread
From: Alexey Khoroshilov @ 2014-03-07 21:11 UTC (permalink / raw)
  To: Christian Lamparter
  Cc: Alexey Khoroshilov, John W. Linville, linux-wireless, netdev,
	linux-kernel, ldv-project

If p54u_load_firmware() fails, p54u_probe() does not deallocate
already allocated resources. The patch adds proper failure handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/net/wireless/p54/p54usb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index 6e635cfa24c8..5df74503fd4f 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -1053,6 +1053,10 @@ static int p54u_probe(struct usb_interface *intf,
 		priv->upload_fw = p54u_upload_firmware_net2280;
 	}
 	err = p54u_load_firmware(dev, intf);
+	if (err) {
+		usb_put_dev(udev);
+		p54_free_common(dev);
+	}
 	return err;
 }
 
-- 
1.8.3.2

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

* Re: [PATCH] p54usb: fix leaks at failure path in p54u_probe()
  2014-03-07 21:11 [PATCH] p54usb: fix leaks at failure path in p54u_probe() Alexey Khoroshilov
@ 2014-03-07 21:27 ` Christian Lamparter
  2014-03-08 22:44 ` Krishna Chaitanya
  1 sibling, 0 replies; 6+ messages in thread
From: Christian Lamparter @ 2014-03-07 21:27 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: John W. Linville, linux-wireless, netdev, linux-kernel,
	ldv-project

On Saturday, March 08, 2014 01:11:49 AM Alexey Khoroshilov wrote:
> If p54u_load_firmware() fails, p54u_probe() does not deallocate
> already allocated resources. The patch adds proper failure handling.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Christian Lamparter <chunkeey@googlemail.com>

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

* Re: [PATCH] p54usb: fix leaks at failure path in p54u_probe()
  2014-03-07 21:11 [PATCH] p54usb: fix leaks at failure path in p54u_probe() Alexey Khoroshilov
  2014-03-07 21:27 ` Christian Lamparter
@ 2014-03-08 22:44 ` Krishna Chaitanya
  2014-03-08 23:01   ` Alexey Khoroshilov
  2014-03-08 23:08   ` Christian Lamparter
  1 sibling, 2 replies; 6+ messages in thread
From: Krishna Chaitanya @ 2014-03-08 22:44 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Christian Lamparter, John W. Linville, linux-wireless, netdev,
	linux-kernel, ldv-project

On Sat, Mar 8, 2014 at 2:41 AM, Alexey Khoroshilov
<khoroshilov@ispras.ru> wrote:
> If p54u_load_firmware() fails, p54u_probe() does not deallocate
> already allocated resources. The patch adds proper failure handling.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  drivers/net/wireless/p54/p54usb.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
> index 6e635cfa24c8..5df74503fd4f 100644
> --- a/drivers/net/wireless/p54/p54usb.c
> +++ b/drivers/net/wireless/p54/p54usb.c
> @@ -1053,6 +1053,10 @@ static int p54u_probe(struct usb_interface *intf,
>                 priv->upload_fw = p54u_upload_firmware_net2280;
>         }
>         err = p54u_load_firmware(dev, intf);
> +       if (err) {
> +               usb_put_dev(udev);
> +               p54_free_common(dev);
> +       }
>         return err;
>  }
The load_firmware puts down the reference
in case of error. Only free is required here.

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

* Re: [PATCH] p54usb: fix leaks at failure path in p54u_probe()
  2014-03-08 22:44 ` Krishna Chaitanya
@ 2014-03-08 23:01   ` Alexey Khoroshilov
  2014-03-08 23:08   ` Christian Lamparter
  1 sibling, 0 replies; 6+ messages in thread
From: Alexey Khoroshilov @ 2014-03-08 23:01 UTC (permalink / raw)
  To: Krishna Chaitanya
  Cc: Christian Lamparter, John W. Linville, linux-wireless, netdev,
	linux-kernel, ldv-project

On 09.03.2014 02:44, Krishna Chaitanya wrote:
> On Sat, Mar 8, 2014 at 2:41 AM, Alexey Khoroshilov
> <khoroshilov@ispras.ru> wrote:
>> If p54u_load_firmware() fails, p54u_probe() does not deallocate
>> already allocated resources. The patch adds proper failure handling.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
>> ---
>>  drivers/net/wireless/p54/p54usb.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
>> index 6e635cfa24c8..5df74503fd4f 100644
>> --- a/drivers/net/wireless/p54/p54usb.c
>> +++ b/drivers/net/wireless/p54/p54usb.c
>> @@ -1053,6 +1053,10 @@ static int p54u_probe(struct usb_interface *intf,
>>                 priv->upload_fw = p54u_upload_firmware_net2280;
>>         }
>>         err = p54u_load_firmware(dev, intf);
>> +       if (err) {
>> +               usb_put_dev(udev);
>> +               p54_free_common(dev);
>> +       }
>>         return err;
>>  }
> The load_firmware puts down the reference
> in case of error. Only free is required here.
No, p54u_load_firmware() puts down reference that was got up by itself.
So we still have to put down reference got up in p54u_probe().

--
Alexey

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

* Re: [PATCH] p54usb: fix leaks at failure path in p54u_probe()
  2014-03-08 22:44 ` Krishna Chaitanya
  2014-03-08 23:01   ` Alexey Khoroshilov
@ 2014-03-08 23:08   ` Christian Lamparter
  2014-03-08 23:10     ` Krishna Chaitanya
  1 sibling, 1 reply; 6+ messages in thread
From: Christian Lamparter @ 2014-03-08 23:08 UTC (permalink / raw)
  To: Krishna Chaitanya
  Cc: Alexey Khoroshilov, John W. Linville, linux-wireless, netdev,
	linux-kernel, ldv-project

On Sunday, March 09, 2014 04:14:32 AM Krishna Chaitanya wrote:
> On Sat, Mar 8, 2014 at 2:41 AM, Alexey Khoroshilov
> <khoroshilov@ispras.ru> wrote:
> > If p54u_load_firmware() fails, p54u_probe() does not deallocate
> > already allocated resources. The patch adds proper failure handling.
> >
> > Found by Linux Driver Verification project (linuxtesting.org).
> >
> > Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> > ---
> >  drivers/net/wireless/p54/p54usb.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
> > index 6e635cfa24c8..5df74503fd4f 100644
> > --- a/drivers/net/wireless/p54/p54usb.c
> > +++ b/drivers/net/wireless/p54/p54usb.c
> > @@ -1053,6 +1053,10 @@ static int p54u_probe(struct usb_interface *intf,
> >                 priv->upload_fw = p54u_upload_firmware_net2280;
> >         }
> >         err = p54u_load_firmware(dev, intf);
> > +       if (err) {
> > +               usb_put_dev(udev);
> > +               p54_free_common(dev);
> > +       }
> >         return err;
> >  }
> The load_firmware puts down the reference
> in case of error. Only free is required here.
No, the put is required too... But let me explain:

p54u_load_firmware calls usb_get_dev(udev) before it requests the firmware
load. The Reason is: the firmware callback is usually run in another thread
(usually it's pretty quick, but due to timeouts it could take up to 60 seconds 
- or at least it did when I wrote it). Therefore I found it appropriate to give 
that request callback its "reference++" as it needs the "udev" too (e.g.: for
dev_info, dev_err and releasing the driver if the device couldn't be 
initialized).

Regards,
Christian

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

* Re: [PATCH] p54usb: fix leaks at failure path in p54u_probe()
  2014-03-08 23:08   ` Christian Lamparter
@ 2014-03-08 23:10     ` Krishna Chaitanya
  0 siblings, 0 replies; 6+ messages in thread
From: Krishna Chaitanya @ 2014-03-08 23:10 UTC (permalink / raw)
  To: Christian Lamparter
  Cc: Alexey Khoroshilov, John W. Linville, linux-wireless, netdev,
	linux-kernel, ldv-project

On Sun, Mar 9, 2014 at 4:38 AM, Christian Lamparter
<chunkeey@googlemail.com> wrote:
> On Sunday, March 09, 2014 04:14:32 AM Krishna Chaitanya wrote:
>> On Sat, Mar 8, 2014 at 2:41 AM, Alexey Khoroshilov
>> <khoroshilov@ispras.ru> wrote:
>> > If p54u_load_firmware() fails, p54u_probe() does not deallocate
>> > already allocated resources. The patch adds proper failure handling.
>> >
>> > Found by Linux Driver Verification project (linuxtesting.org).
>> >
>> > Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
>> > ---
>> >  drivers/net/wireless/p54/p54usb.c | 4 ++++
>> >  1 file changed, 4 insertions(+)
>> >
>> > diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
>> > index 6e635cfa24c8..5df74503fd4f 100644
>> > --- a/drivers/net/wireless/p54/p54usb.c
>> > +++ b/drivers/net/wireless/p54/p54usb.c
>> > @@ -1053,6 +1053,10 @@ static int p54u_probe(struct usb_interface *intf,
>> >                 priv->upload_fw = p54u_upload_firmware_net2280;
>> >         }
>> >         err = p54u_load_firmware(dev, intf);
>> > +       if (err) {
>> > +               usb_put_dev(udev);
>> > +               p54_free_common(dev);
>> > +       }
>> >         return err;
>> >  }
>> The load_firmware puts down the reference
>> in case of error. Only free is required here.
> No, the put is required too... But let me explain:
>
> p54u_load_firmware calls usb_get_dev(udev) before it requests the firmware
> load. The Reason is: the firmware callback is usually run in another thread
> (usually it's pretty quick, but due to timeouts it could take up to 60 seconds
> - or at least it did when I wrote it). Therefore I found it appropriate to give
> that request callback its "reference++" as it needs the "udev" too (e.g.: for
> dev_info, dev_err and releasing the driver if the device couldn't be
> initialized).
>
Thanks Christian and Alexey, you answered my next question as well :-).

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

end of thread, other threads:[~2014-03-08 23:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-07 21:11 [PATCH] p54usb: fix leaks at failure path in p54u_probe() Alexey Khoroshilov
2014-03-07 21:27 ` Christian Lamparter
2014-03-08 22:44 ` Krishna Chaitanya
2014-03-08 23:01   ` Alexey Khoroshilov
2014-03-08 23:08   ` Christian Lamparter
2014-03-08 23:10     ` Krishna Chaitanya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).