Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 92588
b: refs/heads/master
c: aa9dbac
h: refs/heads/master
v: v3
  • Loading branch information
Brandon Philips authored and Mauro Carvalho Chehab committed Apr 24, 2008
1 parent 4a009aa commit 7318116
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cbcb565f74cf01d680f83af531490bb2c5375af0
refs/heads/master: aa9dbac426d263b5b86d1684993d18ae187d7588
20 changes: 18 additions & 2 deletions trunk/drivers/media/video/vivi.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct vivi_dev {

struct mutex lock;
spinlock_t slock;
struct mutex mutex;

int users;

Expand Down Expand Up @@ -1036,6 +1037,7 @@ static int vivi_open(struct inode *inode, struct file *file)
struct vivi_dev *dev;
struct vivi_fh *fh;
int i;
int retval = 0;

printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);

Expand All @@ -1045,18 +1047,29 @@ static int vivi_open(struct inode *inode, struct file *file)
return -ENODEV;

found:
/* If more than one user, mutex should be added */
mutex_lock(&dev->mutex);
dev->users++;

if (dev->users > 1) {
dev->users--;
retval = -EBUSY;
goto unlock;
}

dprintk(dev, 1, "open minor=%d type=%s users=%d\n", minor,
v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);

/* allocate + initialize per filehandle data */
fh = kzalloc(sizeof(*fh), GFP_KERNEL);
if (NULL == fh) {
dev->users--;
return -ENOMEM;
retval = -ENOMEM;
goto unlock;
}
unlock:
mutex_unlock(&dev->mutex);
if (retval)
return retval;

file->private_data = fh;
fh->dev = dev;
Expand Down Expand Up @@ -1128,7 +1141,9 @@ static int vivi_close(struct inode *inode, struct file *file)

kfree(fh);

mutex_lock(&dev->mutex);
dev->users--;
mutex_unlock(&dev->mutex);

dprintk(dev, 1, "close called (minor=%d, users=%d)\n",
minor, dev->users);
Expand Down Expand Up @@ -1243,6 +1258,7 @@ static int __init vivi_init(void)
/* initialize locks */
mutex_init(&dev->lock);
spin_lock_init(&dev->slock);
mutex_init(&dev->mutex);

dev->vidq.timeout.function = vivi_vid_timeout;
dev->vidq.timeout.data = (unsigned long)dev;
Expand Down

0 comments on commit 7318116

Please sign in to comment.