mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/5] usb: f_fs: fix memory leak when ep changes during transfer
@ 2016-01-04 21:41 Michal Nazarewicz
  2016-01-04 21:41 ` [PATCH 2/5] usb: f_fs: fix ffs_epfile_io returning success on req alloc failure Michal Nazarewicz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michal Nazarewicz @ 2016-01-04 21:41 UTC (permalink / raw)
  To: Felipe Balbi, Du, Changbin
  Cc: Greg Kroah-Hartman, Al Viro, Robert Baldyga, linux-usb,
	linux-kernel, Michal Nazarewicz

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>
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index cf43e9e..d1a4a86 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -763,7 +763,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
 	if (epfile->ep != ep) {
 		/* In the meantime, endpoint got disabled or changed. */
 		ret = -ESHUTDOWN;
-		spin_unlock_irq(&epfile->ffs->eps_lock);
+		goto error_lock;
 	} else if (halt) {
 		/* Halt */
 		if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep))
-- 
2.6.0.rc2.230.g3dd15c0


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

end of thread, other threads:[~2016-01-04 21:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-04 21:41 [PATCH 1/5] usb: f_fs: fix memory leak when ep changes during transfer Michal Nazarewicz
2016-01-04 21:41 ` [PATCH 2/5] usb: f_fs: fix ffs_epfile_io returning success on req alloc failure Michal Nazarewicz
2016-01-04 21:41 ` [PATCH 3/5] usb: f_fs: replace unnecessary goto with a return Michal Nazarewicz
2016-01-04 21:41 ` [PATCH 4/5] usb: f_fs: refactor ffs_epfile_io Michal Nazarewicz
2016-01-04 21:41 ` [PATCH 5/5] usb: f_fs: avoid race condition with ffs_epfile_io_complete Michal Nazarewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®