USB: rio500: fix memory leak in close after disconnect

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>
This commit is contained in:
Oliver Neukum 2019-05-09 11:30:59 +02:00 коммит произвёл Greg Kroah-Hartman
Родитель 3864d33943
Коммит e0feb73428
1 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -86,9 +86,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));
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;
}