* [PATCH] staging: ft1000: fix memory leak on error path in ft1000_probe()
@ 2013-06-10 19:29 Alexey Khoroshilov
2013-06-10 20:40 ` Belisko Marek
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Khoroshilov @ 2013-06-10 19:29 UTC (permalink / raw)
To: Marek Belisko, Greg Kroah-Hartman
Cc: Alexey Khoroshilov, devel, linux-kernel, ldv-project
ft1000dev->tx_urb and ft1000dev->rx_urb are not deallocated
if something goes wrong in ft1000_probe(). Also there is no
check for success of urb allocation. The patch fixes the both issues.
By the way, there is no sense in GFP_ATOMIC for urb allocation here,
so it is changed to GFP_KERNEL.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
index 614db55..29a7cd2 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
@@ -79,8 +79,12 @@ static int ft1000_probe(struct usb_interface *interface,
ft1000dev->dev = dev;
ft1000dev->status = 0;
ft1000dev->net = NULL;
- ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
- ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC);
+ ft1000dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
+ ft1000dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
+ if (!ft1000dev->tx_urb || !ft1000dev->rx_urb) {
+ ret = -ENOMEM;
+ goto err_fw;
+ }
DEBUG("ft1000_probe is called\n");
numaltsetting = interface->num_altsetting;
@@ -209,6 +213,8 @@ err_thread:
err_load:
kfree(pFileStart);
err_fw:
+ usb_free_urb(ft1000dev->rx_urb);
+ usb_free_urb(ft1000dev->tx_urb);
kfree(ft1000dev);
return ret;
}
--
1.8.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: ft1000: fix memory leak on error path in ft1000_probe()
2013-06-10 19:29 [PATCH] staging: ft1000: fix memory leak on error path in ft1000_probe() Alexey Khoroshilov
@ 2013-06-10 20:40 ` Belisko Marek
2013-06-11 6:37 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Belisko Marek @ 2013-06-10 20:40 UTC (permalink / raw)
To: Alexey Khoroshilov; +Cc: Greg Kroah-Hartman, devel, LKML, ldv-project
Hi Alexey,
On Mon, Jun 10, 2013 at 9:29 PM, Alexey Khoroshilov
<khoroshilov@ispras.ru> wrote:
> ft1000dev->tx_urb and ft1000dev->rx_urb are not deallocated
> if something goes wrong in ft1000_probe(). Also there is no
> check for success of urb allocation. The patch fixes the both issues.
>
> By the way, there is no sense in GFP_ATOMIC for urb allocation here,
> so it is changed to GFP_KERNEL.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
> drivers/staging/ft1000/ft1000-usb/ft1000_usb.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
> index 614db55..29a7cd2 100644
> --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
> +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
> @@ -79,8 +79,12 @@ static int ft1000_probe(struct usb_interface *interface,
> ft1000dev->dev = dev;
> ft1000dev->status = 0;
> ft1000dev->net = NULL;
> - ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
> - ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC);
> + ft1000dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
Can we check return value for tx here? If allocation fails it makes no sense to
try allocate also rx. Otherwise looks good. Thanks.
> + ft1000dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
Same for rx here.
> + if (!ft1000dev->tx_urb || !ft1000dev->rx_urb) {
> + ret = -ENOMEM;
> + goto err_fw;
> + }
>
> DEBUG("ft1000_probe is called\n");
> numaltsetting = interface->num_altsetting;
> @@ -209,6 +213,8 @@ err_thread:
> err_load:
> kfree(pFileStart);
> err_fw:
> + usb_free_urb(ft1000dev->rx_urb);
> + usb_free_urb(ft1000dev->tx_urb);
> kfree(ft1000dev);
> return ret;
> }
> --
> 1.8.1.2
>
marek
--
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer
Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
twitter: #opennandra
web: http://open-nandra.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: ft1000: fix memory leak on error path in ft1000_probe()
2013-06-10 20:40 ` Belisko Marek
@ 2013-06-11 6:37 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2013-06-11 6:37 UTC (permalink / raw)
To: Belisko Marek; +Cc: Alexey Khoroshilov, devel, ldv-project, LKML
On Mon, Jun 10, 2013 at 10:40:19PM +0200, Belisko Marek wrote:
> Hi Alexey,
>
> On Mon, Jun 10, 2013 at 9:29 PM, Alexey Khoroshilov
> <khoroshilov@ispras.ru> wrote:
> > ft1000dev->tx_urb and ft1000dev->rx_urb are not deallocated
> > if something goes wrong in ft1000_probe(). Also there is no
> > check for success of urb allocation. The patch fixes the both issues.
> >
> > By the way, there is no sense in GFP_ATOMIC for urb allocation here,
> > so it is changed to GFP_KERNEL.
> >
> > Found by Linux Driver Verification project (linuxtesting.org).
> >
> > Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> > ---
> > drivers/staging/ft1000/ft1000-usb/ft1000_usb.c | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
> > index 614db55..29a7cd2 100644
> > --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
> > +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
> > @@ -79,8 +79,12 @@ static int ft1000_probe(struct usb_interface *interface,
> > ft1000dev->dev = dev;
> > ft1000dev->status = 0;
> > ft1000dev->net = NULL;
> > - ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
> > - ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC);
> > + ft1000dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
> Can we check return value for tx here? If allocation fails it makes no sense to
> try allocate also rx. Otherwise looks good. Thanks.
> > + ft1000dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
> Same for rx here.
> > + if (!ft1000dev->tx_urb || !ft1000dev->rx_urb) {
Both of these allocations are checked here, so it's fine, no need to
change anything.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-06-11 6:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-10 19:29 [PATCH] staging: ft1000: fix memory leak on error path in ft1000_probe() Alexey Khoroshilov
2013-06-10 20:40 ` Belisko Marek
2013-06-11 6:37 ` Greg Kroah-Hartman
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).