From: Oliver Neukum Date: Thu, 9 May 2019 09:30:59 +0000 (+0200) Subject: USB: rio500: fix memory leak in close after disconnect X-Git-Tag: v4.19.49~61 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4c1b4a61f78f2f743ccd42244a21add70c6c702;p=platform%2Fkernel%2Flinux-rpi3.git USB: rio500: fix memory leak in close after disconnect commit e0feb73428b69322dd5caae90b0207de369b5575 upstream. If a disconnected device is closed, rio_close() must free the buffers. Signed-off-by: Oliver Neukum Cc: stable Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c index 1d397d9..a32d61a 100644 --- a/drivers/usb/misc/rio500.c +++ b/drivers/usb/misc/rio500.c @@ -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)); - 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; }