Commit aeab2790 authored by Stelian Pop's avatar Stelian Pop Committed by Linus Torvalds

[PATCH] meye: do lock properly when waiting for buffers

Signed-off-by: default avatarStelian Pop <stelian@popies.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 8ffe47d6
...@@ -929,19 +929,25 @@ static int meye_do_ioctl(struct inode *inode, struct file *file, ...@@ -929,19 +929,25 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
if (*i < 0 || *i >= gbuffers) if (*i < 0 || *i >= gbuffers)
return -EINVAL; return -EINVAL;
down(&meye.lock);
switch (meye.grab_buffer[*i].state) { switch (meye.grab_buffer[*i].state) {
case MEYE_BUF_UNUSED: case MEYE_BUF_UNUSED:
up(&meye.lock);
return -EINVAL; return -EINVAL;
case MEYE_BUF_USING: case MEYE_BUF_USING:
if (wait_event_interruptible(meye.proc_list, if (wait_event_interruptible(meye.proc_list,
(meye.grab_buffer[*i].state != MEYE_BUF_USING))) (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
up(&meye.lock);
return -EINTR; return -EINTR;
}
/* fall through */ /* fall through */
case MEYE_BUF_DONE: case MEYE_BUF_DONE:
meye.grab_buffer[*i].state = MEYE_BUF_UNUSED; meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int)); kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
} }
up(&meye.lock);
break; break;
} }
...@@ -1059,20 +1065,25 @@ static int meye_do_ioctl(struct inode *inode, struct file *file, ...@@ -1059,20 +1065,25 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
if (*i < 0 || *i >= gbuffers) if (*i < 0 || *i >= gbuffers)
return -EINVAL; return -EINVAL;
down(&meye.lock);
switch (meye.grab_buffer[*i].state) { switch (meye.grab_buffer[*i].state) {
case MEYE_BUF_UNUSED: case MEYE_BUF_UNUSED:
up(&meye.lock);
return -EINVAL; return -EINVAL;
case MEYE_BUF_USING: case MEYE_BUF_USING:
if (wait_event_interruptible(meye.proc_list, if (wait_event_interruptible(meye.proc_list,
(meye.grab_buffer[*i].state != MEYE_BUF_USING))) (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
up(&meye.lock);
return -EINTR; return -EINTR;
}
/* fall through */ /* fall through */
case MEYE_BUF_DONE: case MEYE_BUF_DONE:
meye.grab_buffer[*i].state = MEYE_BUF_UNUSED; meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int)); kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
} }
*i = meye.grab_buffer[*i].size; *i = meye.grab_buffer[*i].size;
up(&meye.lock);
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment