Skip to content

Commit

Permalink
V4L/DVB (8613): v4l: move BKL down to the driver level.
Browse files Browse the repository at this point in the history
The BKL is now moved from the video_open function in v4l2-dev.c to the
various drivers. It seems about a third of the drivers already has a
lock of some sort protecting the open(), another third uses
video_exclusive_open (yuck!) and the last third required adding the
BKL in their open function.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Oct 12, 2008
1 parent 95f73c5 commit d56dc61
Show file tree
Hide file tree
Showing 26 changed files with 146 additions and 25 deletions.
3 changes: 3 additions & 0 deletions drivers/media/radio/dsbr100.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,18 @@ static int usb_dsbr100_open(struct inode *inode, struct file *file)
{
struct dsbr100_device *radio=video_get_drvdata(video_devdata(file));

lock_kernel();
radio->users = 1;
radio->muted = 1;

if (dsbr100_start(radio)<0) {
warn("Radio did not start up properly");
radio->users = 0;
unlock_kernel();
return -EIO;
}
dsbr100_setfreq(radio, radio->curfreq);
unlock_kernel();
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/media/radio/radio-si470x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ static int si470x_fops_open(struct inode *inode, struct file *file)
struct si470x_device *radio = video_get_drvdata(video_devdata(file));
int retval;

lock_kernel();
radio->users++;

retval = usb_autopm_get_interface(radio->intf);
Expand All @@ -1090,6 +1091,7 @@ static int si470x_fops_open(struct inode *inode, struct file *file)
}

done:
unlock_kernel();
return retval;
}

Expand Down
20 changes: 16 additions & 4 deletions drivers/media/video/bt8xx/bttv-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,7 @@ static int bttv_open(struct inode *inode, struct file *file)

dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor);

lock_kernel();
for (i = 0; i < bttv_num; i++) {
if (bttvs[i].video_dev &&
bttvs[i].video_dev->minor == minor) {
Expand All @@ -3241,16 +3242,20 @@ static int bttv_open(struct inode *inode, struct file *file)
break;
}
}
if (NULL == btv)
if (NULL == btv) {
unlock_kernel();
return -ENODEV;
}

dprintk(KERN_DEBUG "bttv%d: open called (type=%s)\n",
btv->c.nr,v4l2_type_names[type]);

/* allocate per filehandle data */
fh = kmalloc(sizeof(*fh),GFP_KERNEL);
if (NULL == fh)
if (NULL == fh) {
unlock_kernel();
return -ENOMEM;
}
file->private_data = fh;
*fh = btv->init;
fh->type = type;
Expand Down Expand Up @@ -3290,6 +3295,7 @@ static int bttv_open(struct inode *inode, struct file *file)
bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);

bttv_field_count(btv);
unlock_kernel();
return 0;
}

Expand Down Expand Up @@ -3430,21 +3436,26 @@ static int radio_open(struct inode *inode, struct file *file)

dprintk("bttv: open minor=%d\n",minor);

lock_kernel();
for (i = 0; i < bttv_num; i++) {
if (bttvs[i].radio_dev && bttvs[i].radio_dev->minor == minor) {
btv = &bttvs[i];
break;
}
}
if (NULL == btv)
if (NULL == btv) {
unlock_kernel();
return -ENODEV;
}

dprintk("bttv%d: open called (radio)\n",btv->c.nr);

/* allocate per filehandle data */
fh = kmalloc(sizeof(*fh), GFP_KERNEL);
if (NULL == fh)
if (NULL == fh) {
unlock_kernel();
return -ENOMEM;
}
file->private_data = fh;
*fh = btv->init;
v4l2_prio_open(&btv->prio, &fh->prio);
Expand All @@ -3457,6 +3468,7 @@ static int radio_open(struct inode *inode, struct file *file)
audio_input(btv,TVAUDIO_INPUT_RADIO);

mutex_unlock(&btv->lock);
unlock_kernel();
return 0;
}

Expand Down
6 changes: 5 additions & 1 deletion drivers/media/video/cafe_ccic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,9 +1476,12 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
{
struct cafe_camera *cam;

lock_kernel();
cam = cafe_find_dev(iminor(inode));
if (cam == NULL)
if (cam == NULL) {
unlock_kernel();
return -ENODEV;
}
filp->private_data = cam;

mutex_lock(&cam->s_mutex);
Expand All @@ -1490,6 +1493,7 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
}
(cam->users)++;
mutex_unlock(&cam->s_mutex);
unlock_kernel();
return 0;
}

Expand Down
10 changes: 8 additions & 2 deletions drivers/media/video/cx23885/cx23885-417.c
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,7 @@ static int mpeg_open(struct inode *inode, struct file *file)

dprintk(2, "%s()\n", __func__);

lock_kernel();
list_for_each(list, &cx23885_devlist) {
h = list_entry(list, struct cx23885_dev, devlist);
if (h->v4l_device->minor == minor) {
Expand All @@ -1591,13 +1592,17 @@ static int mpeg_open(struct inode *inode, struct file *file)
}
}

if (dev == NULL)
if (dev == NULL) {
unlock_kernel();
return -ENODEV;
}

/* allocate + initialize per filehandle data */
fh = kzalloc(sizeof(*fh), GFP_KERNEL);
if (NULL == fh)
if (NULL == fh) {
unlock_kernel();
return -ENOMEM;
}

file->private_data = fh;
fh->dev = dev;
Expand All @@ -1608,6 +1613,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
V4L2_FIELD_INTERLACED,
sizeof(struct cx23885_buffer),
fh);
unlock_kernel();

return 0;
}
Expand Down
10 changes: 8 additions & 2 deletions drivers/media/video/cx23885/cx23885-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ static int video_open(struct inode *inode, struct file *file)
enum v4l2_buf_type type = 0;
int radio = 0;

lock_kernel();
list_for_each(list, &cx23885_devlist) {
h = list_entry(list, struct cx23885_dev, devlist);
if (h->video_dev->minor == minor) {
Expand All @@ -748,16 +749,20 @@ static int video_open(struct inode *inode, struct file *file)
dev = h;
}
}
if (NULL == dev)
if (NULL == dev) {
unlock_kernel();
return -ENODEV;
}

dprintk(1, "open minor=%d radio=%d type=%s\n",
minor, radio, v4l2_type_names[type]);

/* allocate + initialize per filehandle data */
fh = kzalloc(sizeof(*fh), GFP_KERNEL);
if (NULL == fh)
if (NULL == fh) {
unlock_kernel();
return -ENOMEM;
}
file->private_data = fh;
fh->dev = dev;
fh->radio = radio;
Expand All @@ -775,6 +780,7 @@ static int video_open(struct inode *inode, struct file *file)

dprintk(1, "post videobuf_queue_init()\n");

unlock_kernel();

return 0;
}
Expand Down
8 changes: 7 additions & 1 deletion drivers/media/video/cx88/cx88-blackbird.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,12 +1057,15 @@ static int mpeg_open(struct inode *inode, struct file *file)
struct cx8802_driver *drv = NULL;
int err;

lock_kernel();
dev = cx8802_get_device(inode);

dprintk( 1, "%s\n", __func__);

if (dev == NULL)
if (dev == NULL) {
unlock_kernel();
return -ENODEV;
}

/* Make sure we can acquire the hardware */
drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD);
Expand All @@ -1077,6 +1080,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
if (blackbird_initialize_codec(dev) < 0) {
if (drv)
drv->request_release(drv);
unlock_kernel();
return -EINVAL;
}
dprintk(1,"open minor=%d\n",minor);
Expand All @@ -1086,6 +1090,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
if (NULL == fh) {
if (drv)
drv->request_release(drv);
unlock_kernel();
return -ENOMEM;
}
file->private_data = fh;
Expand All @@ -1101,6 +1106,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
/* FIXME: locking against other video device */
cx88_set_scale(dev->core, dev->width, dev->height,
fh->mpegq.field);
unlock_kernel();

return 0;
}
Expand Down
10 changes: 8 additions & 2 deletions drivers/media/video/cx88/cx88-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ static int video_open(struct inode *inode, struct file *file)
enum v4l2_buf_type type = 0;
int radio = 0;

lock_kernel();
list_for_each_entry(h, &cx8800_devlist, devlist) {
if (h->video_dev->minor == minor) {
dev = h;
Expand All @@ -788,8 +789,10 @@ static int video_open(struct inode *inode, struct file *file)
dev = h;
}
}
if (NULL == dev)
if (NULL == dev) {
unlock_kernel();
return -ENODEV;
}

core = dev->core;

Expand All @@ -798,8 +801,10 @@ static int video_open(struct inode *inode, struct file *file)

/* allocate + initialize per filehandle data */
fh = kzalloc(sizeof(*fh),GFP_KERNEL);
if (NULL == fh)
if (NULL == fh) {
unlock_kernel();
return -ENOMEM;
}
file->private_data = fh;
fh->dev = dev;
fh->radio = radio;
Expand Down Expand Up @@ -832,6 +837,7 @@ static int video_open(struct inode *inode, struct file *file)
cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL);
}
unlock_kernel();

return 0;
}
Expand Down
7 changes: 6 additions & 1 deletion drivers/media/video/em28xx/em28xx-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
struct em28xx_fh *fh;
enum v4l2_buf_type fh_type = 0;

lock_kernel();
list_for_each_entry(h, &em28xx_devlist, devlist) {
if (h->vdev->minor == minor) {
dev = h;
Expand All @@ -1527,8 +1528,10 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
dev = h;
}
}
if (NULL == dev)
if (NULL == dev) {
unlock_kernel();
return -ENODEV;
}

em28xx_videodbg("open minor=%d type=%s users=%d\n",
minor, v4l2_type_names[fh_type], dev->users);
Expand All @@ -1537,6 +1540,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
if (!fh) {
em28xx_errdev("em28xx-video.c: Out of memory?!\n");
unlock_kernel();
return -ENOMEM;
}
mutex_lock(&dev->lock);
Expand Down Expand Up @@ -1573,6 +1577,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
sizeof(struct em28xx_buffer), fh);

mutex_unlock(&dev->lock);
unlock_kernel();

return errCode;
}
Expand Down
7 changes: 6 additions & 1 deletion drivers/media/video/meye.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,22 +845,27 @@ static int meye_open(struct inode *inode, struct file *file)
{
int i, err;

lock_kernel();
err = video_exclusive_open(inode, file);
if (err < 0)
if (err < 0) {
unlock_kernel();
return err;
}

mchip_hic_stop();

if (mchip_dma_alloc()) {
printk(KERN_ERR "meye: mchip framebuffer allocation failed\n");
video_exclusive_release(inode, file);
unlock_kernel();
return -ENOBUFS;
}

for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
kfifo_reset(meye.grabq);
kfifo_reset(meye.doneq);
unlock_kernel();
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions drivers/media/video/pvrusb2/pvrusb2-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
unsigned int input_cnt,idx;
int ret = 0;

lock_kernel();
dip = container_of(video_devdata(file),struct pvr2_v4l2_dev,devbase);

vp = dip->v4lp;
Expand All @@ -942,11 +943,13 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
if (!pvr2_hdw_dev_ok(hdw)) {
pvr2_trace(PVR2_TRACE_OPEN_CLOSE,
"pvr2_v4l2_open: hardware not ready");
unlock_kernel();
return -EIO;
}

fhp = kzalloc(sizeof(*fhp),GFP_KERNEL);
if (!fhp) {
unlock_kernel();
return -ENOMEM;
}

Expand Down Expand Up @@ -976,6 +979,7 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
fhp);

kfree(fhp);
unlock_kernel();
return ret;
}

Expand All @@ -992,6 +996,7 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
"Destroying pvr_v4l2_fh id=%p (input map failure)",
fhp);
kfree(fhp);
unlock_kernel();
return -ENOMEM;
}
input_cnt = 0;
Expand All @@ -1015,6 +1020,7 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
v4l2_prio_open(&vp->prio,&fhp->prio);

fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw);
unlock_kernel();

return 0;
}
Expand Down
Loading

0 comments on commit d56dc61

Please sign in to comment.