aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Abbott <abbotti@mev.co.uk>2012-09-19 14:37:39 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-21 12:29:53 -0400
commitc8cad4c89ee3b15935c532210ae6ebb5c0a2734d (patch)
tree23f09ff365e82104797fc0dccb9084c4eef0088d
parent6f73fbcec27be8b074555e18d9f50c3013e4d802 (diff)
staging: comedi: fix memory leak for saved channel list
When `do_cmd_ioctl()` allocates memory for the kernel copy of a channel list, it frees any previously allocated channel list in `async->cmd.chanlist` and replaces it with the new one. However, if the device is ever removed (or "detached") the cleanup code in `cleanup_device()` in "drivers.c" does not free this memory so it is lost. A sensible place to free the kernel copy of the channel list is in `do_become_nonbusy()` as at that point the comedi asynchronous command associated with the channel list is no longer valid. Free the channel list in `do_become_nonbusy()` instead of `do_cmd_ioctl()` and clear the pointer to prevent it being freed more than once. Note that `cleanup_device()` could be called at an inappropriate time while the comedi device is open, but that's a separate bug not related to this this patch. Cc: stable@vger.kernel.org Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/comedi_fops.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index f496f4d96c83..c2a32cf95a82 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1195,7 +1195,6 @@ static int do_cmd_ioctl(struct comedi_device *dev,
1195 goto cleanup; 1195 goto cleanup;
1196 } 1196 }
1197 1197
1198 kfree(async->cmd.chanlist);
1199 async->cmd = cmd; 1198 async->cmd = cmd;
1200 async->cmd.data = NULL; 1199 async->cmd.data = NULL;
1201 /* load channel/gain list */ 1200 /* load channel/gain list */
@@ -2033,6 +2032,8 @@ static void do_become_nonbusy(struct comedi_device *dev,
2033 if (async) { 2032 if (async) {
2034 comedi_reset_async_buf(async); 2033 comedi_reset_async_buf(async);
2035 async->inttrig = NULL; 2034 async->inttrig = NULL;
2035 kfree(async->cmd.chanlist);
2036 async->cmd.chanlist = NULL;
2036 } else { 2037 } else {
2037 dev_err(dev->class_dev, 2038 dev_err(dev->class_dev,
2038 "BUG: (?) do_become_nonbusy called with async=NULL\n"); 2039 "BUG: (?) do_become_nonbusy called with async=NULL\n");