V4L/DVB (3569): PATCH: switch cpia2 to mutexes and use ioctl 32 compat lib func
Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
This commit is contained in:
parent
bc2c7c365b
commit
2ae151911e
|
@ -381,7 +381,7 @@ struct cpia2_fh {
|
||||||
|
|
||||||
struct camera_data {
|
struct camera_data {
|
||||||
/* locks */
|
/* locks */
|
||||||
struct semaphore busy_lock; /* guard against SMP multithreading */
|
struct mutex busy_lock; /* guard against SMP multithreading */
|
||||||
struct v4l2_prio_state prio;
|
struct v4l2_prio_state prio;
|
||||||
|
|
||||||
/* camera status */
|
/* camera status */
|
||||||
|
|
|
@ -2238,7 +2238,7 @@ struct camera_data *cpia2_init_camera_struct(void)
|
||||||
memset(cam, 0, sizeof(struct camera_data));
|
memset(cam, 0, sizeof(struct camera_data));
|
||||||
|
|
||||||
cam->present = 1;
|
cam->present = 1;
|
||||||
init_MUTEX(&cam->busy_lock);
|
mutex_init(&cam->busy_lock);
|
||||||
init_waitqueue_head(&cam->wq_stream);
|
init_waitqueue_head(&cam->wq_stream);
|
||||||
|
|
||||||
return cam;
|
return cam;
|
||||||
|
@ -2371,12 +2371,12 @@ long cpia2_read(struct camera_data *cam,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make this _really_ smp and multithread-safe */
|
/* make this _really_ smp and multithread-safe */
|
||||||
if (down_interruptible(&cam->busy_lock))
|
if (mutex_lock_interruptible(&cam->busy_lock))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
if (!cam->present) {
|
if (!cam->present) {
|
||||||
LOG("%s: camera removed\n",__FUNCTION__);
|
LOG("%s: camera removed\n",__FUNCTION__);
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return 0; /* EOF */
|
return 0; /* EOF */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2389,34 +2389,34 @@ long cpia2_read(struct camera_data *cam,
|
||||||
/* Copy cam->curbuff in case it changes while we're processing */
|
/* Copy cam->curbuff in case it changes while we're processing */
|
||||||
frame = cam->curbuff;
|
frame = cam->curbuff;
|
||||||
if (noblock && frame->status != FRAME_READY) {
|
if (noblock && frame->status != FRAME_READY) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(frame->status != FRAME_READY) {
|
if(frame->status != FRAME_READY) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
wait_event_interruptible(cam->wq_stream,
|
wait_event_interruptible(cam->wq_stream,
|
||||||
!cam->present ||
|
!cam->present ||
|
||||||
(frame = cam->curbuff)->status == FRAME_READY);
|
(frame = cam->curbuff)->status == FRAME_READY);
|
||||||
if (signal_pending(current))
|
if (signal_pending(current))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
/* make this _really_ smp and multithread-safe */
|
/* make this _really_ smp and multithread-safe */
|
||||||
if (down_interruptible(&cam->busy_lock)) {
|
if (mutex_lock_interruptible(&cam->busy_lock)) {
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
}
|
}
|
||||||
if(!cam->present) {
|
if(!cam->present) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy data to user space */
|
/* copy data to user space */
|
||||||
if (frame->length > count) {
|
if (frame->length > count) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
if (copy_to_user(buf, frame->data, frame->length)) {
|
if (copy_to_user(buf, frame->data, frame->length)) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2424,7 +2424,7 @@ long cpia2_read(struct camera_data *cam,
|
||||||
|
|
||||||
frame->status = FRAME_EMPTY;
|
frame->status = FRAME_EMPTY;
|
||||||
|
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2443,10 +2443,10 @@ unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
|
||||||
return POLLERR;
|
return POLLERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
down(&cam->busy_lock);
|
mutex_lock(&cam->busy_lock);
|
||||||
|
|
||||||
if(!cam->present) {
|
if(!cam->present) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return POLLHUP;
|
return POLLHUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2456,16 +2456,16 @@ unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
|
||||||
cam->params.camera_state.stream_mode);
|
cam->params.camera_state.stream_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
poll_wait(filp, &cam->wq_stream, wait);
|
poll_wait(filp, &cam->wq_stream, wait);
|
||||||
down(&cam->busy_lock);
|
mutex_lock(&cam->busy_lock);
|
||||||
|
|
||||||
if(!cam->present)
|
if(!cam->present)
|
||||||
status = POLLHUP;
|
status = POLLHUP;
|
||||||
else if(cam->curbuff->status == FRAME_READY)
|
else if(cam->curbuff->status == FRAME_READY)
|
||||||
status = POLLIN | POLLRDNORM;
|
status = POLLIN | POLLRDNORM;
|
||||||
|
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2488,18 +2488,18 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
|
||||||
DBG("mmap offset:%ld size:%ld\n", start_offset, size);
|
DBG("mmap offset:%ld size:%ld\n", start_offset, size);
|
||||||
|
|
||||||
/* make this _really_ smp-safe */
|
/* make this _really_ smp-safe */
|
||||||
if (down_interruptible(&cam->busy_lock))
|
if (mutex_lock_interruptible(&cam->busy_lock))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
if (!cam->present) {
|
if (!cam->present) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > cam->frame_size*cam->num_frames ||
|
if (size > cam->frame_size*cam->num_frames ||
|
||||||
(start_offset % cam->frame_size) != 0 ||
|
(start_offset % cam->frame_size) != 0 ||
|
||||||
(start_offset+size > cam->frame_size*cam->num_frames)) {
|
(start_offset+size > cam->frame_size*cam->num_frames)) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2507,7 +2507,7 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
page = kvirt_to_pa(pos);
|
page = kvirt_to_pa(pos);
|
||||||
if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, PAGE_SIZE, PAGE_SHARED)) {
|
if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, PAGE_SIZE, PAGE_SHARED)) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
start += PAGE_SIZE;
|
start += PAGE_SIZE;
|
||||||
|
@ -2519,7 +2519,7 @@ int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma)
|
||||||
}
|
}
|
||||||
|
|
||||||
cam->mmapped = true;
|
cam->mmapped = true;
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,7 @@ static int cpia2_open(struct inode *inode, struct file *file)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(down_interruptible(&cam->busy_lock))
|
if(mutex_lock_interruptible(&cam->busy_lock))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
if(!cam->present) {
|
if(!cam->present) {
|
||||||
|
@ -299,7 +299,7 @@ skip_init:
|
||||||
cpia2_dbg_dump_registers(cam);
|
cpia2_dbg_dump_registers(cam);
|
||||||
|
|
||||||
err_return:
|
err_return:
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
|
||||||
struct camera_data *cam = video_get_drvdata(dev);
|
struct camera_data *cam = video_get_drvdata(dev);
|
||||||
struct cpia2_fh *fh = file->private_data;
|
struct cpia2_fh *fh = file->private_data;
|
||||||
|
|
||||||
down(&cam->busy_lock);
|
mutex_lock(&cam->busy_lock);
|
||||||
|
|
||||||
if (cam->present &&
|
if (cam->present &&
|
||||||
(cam->open_count == 1
|
(cam->open_count == 1
|
||||||
|
@ -347,7 +347,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -523,11 +523,11 @@ static int sync(struct camera_data *cam, int frame_nr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
wait_event_interruptible(cam->wq_stream,
|
wait_event_interruptible(cam->wq_stream,
|
||||||
!cam->streaming ||
|
!cam->streaming ||
|
||||||
frame->status == FRAME_READY);
|
frame->status == FRAME_READY);
|
||||||
down(&cam->busy_lock);
|
mutex_lock(&cam->busy_lock);
|
||||||
if (signal_pending(current))
|
if (signal_pending(current))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
if(!cam->present)
|
if(!cam->present)
|
||||||
|
@ -1544,11 +1544,11 @@ static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
|
||||||
if(frame < 0) {
|
if(frame < 0) {
|
||||||
/* Wait for a frame to become available */
|
/* Wait for a frame to become available */
|
||||||
struct framebuf *cb=cam->curbuff;
|
struct framebuf *cb=cam->curbuff;
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
wait_event_interruptible(cam->wq_stream,
|
wait_event_interruptible(cam->wq_stream,
|
||||||
!cam->present ||
|
!cam->present ||
|
||||||
(cb=cam->curbuff)->status == FRAME_READY);
|
(cb=cam->curbuff)->status == FRAME_READY);
|
||||||
down(&cam->busy_lock);
|
mutex_lock(&cam->busy_lock);
|
||||||
if (signal_pending(current))
|
if (signal_pending(current))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
if(!cam->present)
|
if(!cam->present)
|
||||||
|
@ -1591,11 +1591,11 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
|
|
||||||
/* make this _really_ smp-safe */
|
/* make this _really_ smp-safe */
|
||||||
if (down_interruptible(&cam->busy_lock))
|
if (mutex_lock_interruptible(&cam->busy_lock))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
if (!cam->present) {
|
if (!cam->present) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1608,7 +1608,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
|
||||||
struct cpia2_fh *fh = file->private_data;
|
struct cpia2_fh *fh = file->private_data;
|
||||||
retval = v4l2_prio_check(&cam->prio, &fh->prio);
|
retval = v4l2_prio_check(&cam->prio, &fh->prio);
|
||||||
if(retval) {
|
if(retval) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1618,7 +1618,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
|
||||||
{
|
{
|
||||||
struct cpia2_fh *fh = file->private_data;
|
struct cpia2_fh *fh = file->private_data;
|
||||||
if(fh->prio != V4L2_PRIORITY_RECORD) {
|
if(fh->prio != V4L2_PRIORITY_RECORD) {
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1847,7 +1847,7 @@ static int cpia2_do_ioctl(struct inode *inode, struct file *file,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
up(&cam->busy_lock);
|
mutex_unlock(&cam->busy_lock);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1924,14 +1924,15 @@ static void reset_camera_struct_v4l(struct camera_data *cam)
|
||||||
* The v4l video device structure initialized for this device
|
* The v4l video device structure initialized for this device
|
||||||
***/
|
***/
|
||||||
static struct file_operations fops_template = {
|
static struct file_operations fops_template = {
|
||||||
.owner= THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.open= cpia2_open,
|
.open = cpia2_open,
|
||||||
.release= cpia2_close,
|
.release = cpia2_close,
|
||||||
.read= cpia2_v4l_read,
|
.read = cpia2_v4l_read,
|
||||||
.poll= cpia2_v4l_poll,
|
.poll = cpia2_v4l_poll,
|
||||||
.ioctl= cpia2_ioctl,
|
.ioctl = cpia2_ioctl,
|
||||||
.llseek= no_llseek,
|
.llseek = no_llseek,
|
||||||
.mmap= cpia2_mmap,
|
.compat_ioctl = v4l_compat_ioctl32,
|
||||||
|
.mmap = cpia2_mmap,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct video_device cpia2_template = {
|
static struct video_device cpia2_template = {
|
||||||
|
|
Loading…
Reference in a new issue