usb: f_fs: fix memory leak when ep changes during transfer
authorMichal Nazarewicz <mina86@mina86.com>
Mon, 4 Jan 2016 19:42:43 +0000 (20:42 +0100)
committerFelipe Balbi <balbi@kernel.org>
Fri, 4 Mar 2016 13:14:31 +0000 (15:14 +0200)
commit3de4e20568171f542adb8d54a47c46ff025ca942
tree9f714516c9623e66aa6b072c071c01aa87b01d0f
parent12496785a414593ff25fd271f37d3a95d2a8058b
usb: f_fs: fix memory leak when ep changes during transfer

In the ffs_epfile_io function, data buffer is allocated for non-halt
requests.  Later, after grabing a mutex, the function checks that
epfile->ep is still ep and if it’s not, it set ret to -ESHUTDOWN and
follow a path including spin_unlock_irq (just after ‘ret = -ESHUTDOWN’),
mutex_unlock (after if-else-if-else chain) and returns ret.  Noticeably,
this does not include freeing of the data buffer.

Fix by introducing a goto which moves control flow to the the end of the
function where spin_unlock_irq, mutex_unlock and kfree are all called.

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
drivers/usb/gadget/function/f_fs.c