Skip to content

Commit e0feb73

Browse files
oneukumgregkh
authored andcommitted
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 <[email protected]> Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3864d33 commit e0feb73

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/usb/misc/rio500.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,22 @@ static int close_rio(struct inode *inode, struct file *file)
8686
{
8787
struct rio_usb_data *rio = &rio_instance;
8888

89-
rio->isopen = 0;
89+
/* against disconnect() */
90+
mutex_lock(&rio500_mutex);
91+
mutex_lock(&(rio->lock));
9092

91-
dev_info(&rio->rio_dev->dev, "Rio closed.\n");
93+
rio->isopen = 0;
94+
if (!rio->present) {
95+
/* cleanup has been delayed */
96+
kfree(rio->ibuf);
97+
kfree(rio->obuf);
98+
rio->ibuf = NULL;
99+
rio->obuf = NULL;
100+
} else {
101+
dev_info(&rio->rio_dev->dev, "Rio closed.\n");
102+
}
103+
mutex_unlock(&(rio->lock));
104+
mutex_unlock(&rio500_mutex);
92105
return 0;
93106
}
94107

0 commit comments

Comments
 (0)