aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFederico Vaga <federico.vaga@gmail.com>2011-10-29 03:45:39 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-11-26 21:34:14 -0500
commitdf30b21cb0eed5ba8a8e0cdfeebc66ba8cde821d (patch)
tree5bd4f9b7050691a53abfff32f1218cadd4425a2b
parent3ffab428f40849ed5f21bcfd7285bdef7902f9ca (diff)
Staging: comedi: fix mmap_count
In comedi_fops, mmap_count is decremented at comedi_vm_ops->close but it is not incremented at comedi_vm_ops->open. This may result in a negative counter. The patch introduces the open method to keep the counter consistent. The bug was triggerd by this sample code: mmap(0, ...., comedi_fd); fork(); exit(0); Acked-by: Alessandro Rubini <rubini@gnudd.com> Signed-off-by: Federico Vaga <federico.vaga@gmail.com> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/comedi/comedi_fops.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 156622a6f162..88caa7376999 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1432,7 +1432,21 @@ static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
1432 return ret; 1432 return ret;
1433} 1433}
1434 1434
1435static void comedi_unmap(struct vm_area_struct *area) 1435
1436static void comedi_vm_open(struct vm_area_struct *area)
1437{
1438 struct comedi_async *async;
1439 struct comedi_device *dev;
1440
1441 async = area->vm_private_data;
1442 dev = async->subdevice->device;
1443
1444 mutex_lock(&dev->mutex);
1445 async->mmap_count++;
1446 mutex_unlock(&dev->mutex);
1447}
1448
1449static void comedi_vm_close(struct vm_area_struct *area)
1436{ 1450{
1437 struct comedi_async *async; 1451 struct comedi_async *async;
1438 struct comedi_device *dev; 1452 struct comedi_device *dev;
@@ -1446,7 +1460,8 @@ static void comedi_unmap(struct vm_area_struct *area)
1446} 1460}
1447 1461
1448static struct vm_operations_struct comedi_vm_ops = { 1462static struct vm_operations_struct comedi_vm_ops = {
1449 .close = comedi_unmap, 1463 .open = comedi_vm_open,
1464 .close = comedi_vm_close,
1450}; 1465};
1451 1466
1452static int comedi_mmap(struct file *file, struct vm_area_struct *vma) 1467static int comedi_mmap(struct file *file, struct vm_area_struct *vma)