Skip to content

Commit

Permalink
Staging: comedi: fix mmap_count
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Federico Vaga authored and Greg Kroah-Hartman committed Nov 27, 2011
1 parent 3ffab42 commit df30b21
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions drivers/staging/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,21 @@ static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
return ret;
}

static void comedi_unmap(struct vm_area_struct *area)

static void comedi_vm_open(struct vm_area_struct *area)
{
struct comedi_async *async;
struct comedi_device *dev;

async = area->vm_private_data;
dev = async->subdevice->device;

mutex_lock(&dev->mutex);
async->mmap_count++;
mutex_unlock(&dev->mutex);
}

static void comedi_vm_close(struct vm_area_struct *area)
{
struct comedi_async *async;
struct comedi_device *dev;
Expand All @@ -1446,7 +1460,8 @@ static void comedi_unmap(struct vm_area_struct *area)
}

static struct vm_operations_struct comedi_vm_ops = {
.close = comedi_unmap,
.open = comedi_vm_open,
.close = comedi_vm_close,
};

static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
Expand Down

0 comments on commit df30b21

Please sign in to comment.