1 From ddeee0b2eec2a51b0712b04de4b39e7bec892a53 Mon Sep 17 00:00:00 2001
2 From: Linus Torvalds <torvalds@linux-foundation.org>
3 Date: Tue, 16 Feb 2010 12:35:07 -0800
4 Subject: USB: usbfs: properly clean up the as structure on error paths
6 From: Linus Torvalds <torvalds@linux-foundation.org>
8 commit ddeee0b2eec2a51b0712b04de4b39e7bec892a53 upstream.
10 I notice that the processcompl_compat() function seems to be leaking the
11 'struct async *as' in the error paths.
13 I think that the calling convention is fundamentally buggered. The
14 caller is the one that did the "reap_as()" to get the as thing, the
15 caller should be the one to free it too.
17 Freeing it in the caller also means that it very clearly always gets
18 freed, and avoids the need for any "free in the error case too".
20 From: Linus Torvalds <torvalds@linux-foundation.org>
21 Cc: Alan Stern <stern@rowland.harvard.edu>
22 Cc: Marcus Meissner <meissner@suse.de>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
26 drivers/usb/core/devio.c | 40 ++++++++++++++++++++++++++--------------
27 1 file changed, 26 insertions(+), 14 deletions(-)
29 --- a/drivers/usb/core/devio.c
30 +++ b/drivers/usb/core/devio.c
31 @@ -1246,14 +1246,11 @@ static int processcompl(struct async *as
37 if (put_user(addr, (void __user * __user *)arg))
46 @@ -1283,8 +1280,11 @@ static struct async *reap_as(struct dev_
47 static int proc_reapurb(struct dev_state *ps, void __user *arg)
49 struct async *as = reap_as(ps);
51 - return processcompl(as, (void __user * __user *)arg);
53 + int retval = processcompl(as, (void __user * __user *)arg);
57 if (signal_pending(current))
60 @@ -1292,11 +1292,16 @@ static int proc_reapurb(struct dev_state
62 static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
67 - if (!(as = async_getcompleted(ps)))
69 - return processcompl(as, (void __user * __user *)arg);
70 + as = async_getcompleted(ps);
73 + retval = processcompl(as, (void __user * __user *)arg);
80 @@ -1369,7 +1374,6 @@ static int processcompl_compat(struct as
85 if (put_user(ptr_to_compat(addr), (u32 __user *)arg))
88 @@ -1378,8 +1382,11 @@ static int processcompl_compat(struct as
89 static int proc_reapurb_compat(struct dev_state *ps, void __user *arg)
91 struct async *as = reap_as(ps);
93 - return processcompl_compat(as, (void __user * __user *)arg);
95 + int retval = processcompl_compat(as, (void __user * __user *)arg);
99 if (signal_pending(current))
102 @@ -1387,11 +1394,16 @@ static int proc_reapurb_compat(struct de
104 static int proc_reapurbnonblock_compat(struct dev_state *ps, void __user *arg)
109 - if (!(as = async_getcompleted(ps)))
111 - return processcompl_compat(as, (void __user * __user *)arg);
113 + as = async_getcompleted(ps);
115 + retval = processcompl_compat(as, (void __user * __user *)arg);