USB: rio500: fix memory leak in close after disconnect
authorOliver Neukum <oneukum@suse.com>
Thu, 9 May 2019 09:30:59 +0000 (11:30 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 9 Jun 2019 07:18:14 +0000 (09:18 +0200)
commit e0feb73428b69322dd5caae90b0207de369b5575 upstream.

If a disconnected device is closed, rio_close() must free
the buffers.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/misc/rio500.c

index 86e0af5842daba8c624bf77141d52fa92228b735..c652a4fdc546c70e8e83e35ccfb9a8dad532cd07 100644 (file)
@@ -99,9 +99,22 @@ static int close_rio(struct inode *inode, struct file *file)
 {
        struct rio_usb_data *rio = &rio_instance;
 
-       rio->isopen = 0;
+       /* against disconnect() */
+       mutex_lock(&rio500_mutex);
+       mutex_lock(&(rio->lock));
 
-       dev_info(&rio->rio_dev->dev, "Rio closed.\n");
+       rio->isopen = 0;
+       if (!rio->present) {
+               /* cleanup has been delayed */
+               kfree(rio->ibuf);
+               kfree(rio->obuf);
+               rio->ibuf = NULL;
+               rio->obuf = NULL;
+       } else {
+               dev_info(&rio->rio_dev->dev, "Rio closed.\n");
+       }
+       mutex_unlock(&(rio->lock));
+       mutex_unlock(&rio500_mutex);
        return 0;
 }