V4L/DVB: radio-si470x: remove the BKL lock used internally at the driver
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/8 V4L/DVB: radio-si470x: remove the BKL lock used internally at the driver
drivers/media/radio/si470x/radio-si470x-usb.c +8 -9
@@ -517,7 +517,7 @@ int si470x_fops_open(struct file *file)struct si470x_device *radio =video_drvdata (file);int retval; -lock_kernel (); +mutex_lock (&radio->lock); radio->users++; retval =usb_autopm_get_interface (radio->intf);
@@ -558,7 +558,7 @@ int si470x_fops_open(struct file *file) } done: -unlock_kernel (); +mutex_unlock (&radio->lock);return retval; }
@@ -577,7 +577,7 @@ int si470x_fops_release(struct file *file) goto done; } -mutex_lock (&radio->disconnect_lock); +mutex_lock (&radio->lock); radio->users--;if (radio->users ==0 ) {/* shutdown interrupt handler */
@@ -591,7 +591,7 @@ int si470x_fops_release(struct file *file)video_unregister_device (radio->videodev);kfree (radio->int_in_buffer);kfree (radio->buffer); -mutex_unlock (&radio->disconnect_lock); +mutex_unlock (&radio->lock);kfree (radio); goto done; }
@@ -603,7 +603,7 @@ int si470x_fops_release(struct file *file) retval =si470x_stop (radio);usb_autopm_put_interface (radio->intf); } -mutex_unlock (&radio->disconnect_lock); +mutex_unlock (&radio->lock); done:return retval; }
@@ -661,7 +661,6 @@ static int si470x_usb_driver_probe(struct usb_interface *intf, radio->disconnected =0 ; radio->usbdev =interface_to_usbdev (intf); radio->intf = intf; -mutex_init (&radio->disconnect_lock);mutex_init (&radio->lock); iface_desc = intf->cur_altsetting;
@@ -830,7 +829,7 @@ static void si470x_usb_driver_disconnect(struct usb_interface *intf) {struct si470x_device *radio =usb_get_intfdata (intf); -mutex_lock (&radio->disconnect_lock); +mutex_lock (&radio->lock); radio->disconnected =1 ;usb_set_intfdata (intf,NULL );if (radio->users ==0 ) {
@@ -843,10 +842,10 @@ static void si470x_usb_driver_disconnect(struct usb_interface *intf)kfree (radio->int_in_buffer);video_unregister_device (radio->videodev);kfree (radio->buffer); -mutex_unlock (&radio->disconnect_lock); +mutex_unlock (&radio->lock);kfree (radio); }else { -mutex_unlock (&radio->disconnect_lock); +mutex_unlock (&radio->lock); } }
drivers/media/radio/si470x/radio-si470x.h +0 -1
@@ -177,7 +177,6 @@ struct si470x_device {/* driver management */ unsigned char disconnected; -struct mutex disconnect_lock;#endif #if defined(CONFIG_I2C_SI470X ) || defined(CONFIG_I2C_SI470X_MODULE )
Signature · 1 line
1.7.1
PATCH 2/8 V4L/DVB: radio-si470x: use unlocked ioctl
In reply to a message not in the archivedrivers/media/radio/si470x/radio-si470x-common.c +22 -5
@@ -408,17 +408,15 @@ done:/* * si470x_rds_on - switch on rds reception */ -int si470x_rds_on (struct si470x_device *radio) +static int si470x_rds_on (struct si470x_device *radio) {int retval;/* sysconfig 1 */ -mutex_lock (&radio->lock); radio->registers[SYSCONFIG1 ] |=SYSCONFIG1_RDS ; retval =si470x_set_register (radio,SYSCONFIG1 );if (retval <0 ) radio->registers[SYSCONFIG1 ] &= ~SYSCONFIG1_RDS ; -mutex_unlock (&radio->lock);return retval; }
@@ -440,6 +438,7 @@ static ssize_t si470x_fops_read(struct file *file, char __user *buf,unsigned int block_count =0 ;/* switch on rds reception */ +mutex_lock (&radio->lock);if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 )si470x_rds_on (radio);
@@ -480,9 +479,9 @@ static ssize_t si470x_fops_read(struct file *file, char __user *buf, buf +=3 ; retval +=3 ; } -mutex_unlock (&radio->lock); done: +mutex_unlock (&radio->lock);return retval; }
@@ -497,8 +496,11 @@ static unsigned int si470x_fops_poll(struct file *file,int retval =0 ;/* switch on rds reception */ + +mutex_lock (&radio->lock);if ((radio->registers[SYSCONFIG1 ] &SYSCONFIG1_RDS ) ==0 )si470x_rds_on (radio); +mutex_unlock (&radio->lock);poll_wait (file, &radio->read_queue, pts);
@@ -516,7 +518,7 @@ static const struct v4l2_file_operations si470x_fops = { .owner = THIS_MODULE, .read = si470x_fops_read, .poll = si470x_fops_poll, - .ioctl = video_ioctl2, + .unlocked_ioctl = video_ioctl2, .open = si470x_fops_open, .release = si470x_fops_release, };
@@ -572,6 +574,7 @@ static int si470x_vidioc_g_ctrl(struct file *file, void *priv,struct si470x_device *radio =video_drvdata (file);int retval =0 ; +mutex_lock (&radio->lock);/* safety checks */ retval =si470x_disconnect_check (radio);if (retval)
@@ -594,6 +597,8 @@ done:if (retval <0 )dev_warn (&radio->videodev->dev,"get control failed with %d\n" , retval); + +mutex_unlock (&radio->lock);return retval; }
@@ -607,6 +612,7 @@ static int si470x_vidioc_s_ctrl(struct file *file, void *priv,struct si470x_device *radio =video_drvdata (file);int retval =0 ; +mutex_lock (&radio->lock);/* safety checks */ retval =si470x_disconnect_check (radio);if (retval)
@@ -633,6 +639,7 @@ done:if (retval <0 )dev_warn (&radio->videodev->dev,"set control failed with %d\n" , retval); +mutex_unlock (&radio->lock);return retval; }
@@ -662,6 +669,7 @@ static int si470x_vidioc_g_tuner(struct file *file, void *priv,struct si470x_device *radio =video_drvdata (file);int retval =0 ; +mutex_lock (&radio->lock);/* safety checks */ retval =si470x_disconnect_check (radio);if (retval)
@@ -737,6 +745,7 @@ done:if (retval <0 )dev_warn (&radio->videodev->dev,"get tuner failed with %d\n" , retval); +mutex_unlock (&radio->lock);return retval; }
@@ -750,6 +759,7 @@ static int si470x_vidioc_s_tuner(struct file *file, void *priv,struct si470x_device *radio =video_drvdata (file);int retval =0 ; +mutex_lock (&radio->lock);/* safety checks */ retval =si470x_disconnect_check (radio);if (retval)
@@ -776,6 +786,7 @@ done:if (retval <0 )dev_warn (&radio->videodev->dev,"set tuner failed with %d\n" , retval); +mutex_unlock (&radio->lock);return retval; }
@@ -790,6 +801,7 @@ static int si470x_vidioc_g_frequency(struct file *file, void *priv,int retval =0 ;/* safety checks */ +mutex_lock (&radio->lock); retval =si470x_disconnect_check (radio);if (retval) goto done;
@@ -806,6 +818,7 @@ done:if (retval <0 )dev_warn (&radio->videodev->dev,"get frequency failed with %d\n" , retval); +mutex_unlock (&radio->lock);return retval; }
@@ -819,6 +832,7 @@ static int si470x_vidioc_s_frequency(struct file *file, void *priv,struct si470x_device *radio =video_drvdata (file);int retval =0 ; +mutex_lock (&radio->lock);/* safety checks */ retval =si470x_disconnect_check (radio);if (retval)
@@ -835,6 +849,7 @@ done:if (retval <0 )dev_warn (&radio->videodev->dev,"set frequency failed with %d\n" , retval); +mutex_unlock (&radio->lock);return retval; }
@@ -848,6 +863,7 @@ static int si470x_vidioc_s_hw_freq_seek(struct file *file, void *priv,struct si470x_device *radio =video_drvdata (file);int retval =0 ; +mutex_lock (&radio->lock);/* safety checks */ retval =si470x_disconnect_check (radio);if (retval)
@@ -864,6 +880,7 @@ done:if (retval <0 )dev_warn (&radio->videodev->dev,"set hardware frequency seek failed with %d\n" , retval); +mutex_unlock (&radio->lock);return retval; }
drivers/media/radio/si470x/radio-si470x.h +0 -1
@@ -220,7 +220,6 @@ int si470x_disconnect_check(struct si470x_device *radio);int si470x_set_freq (struct si470x_device *radio,unsigned int freq);int si470x_start (struct si470x_device *radio);int si470x_stop (struct si470x_device *radio); -int si470x_rds_on (struct si470x_device *radio);int si470x_fops_open (struct file *file);int si470x_fops_release (struct file *file); int si470x_vidioc_querycap(struct file *file, void *priv,
Signature · 1 line
1.7.1
PATCH 3/8 V4L/DVB: bttv-driver: document functions using mutex_lock
In reply to a message not in the archiveThere are a few ancillary static routines used by ioctl functions that takes bttv lock internally. As we'll be adding the same lock for all ioctl's that need, we need to properly document them, to avoid doing double locks
drivers/media/video/bt8xx/bttv-driver.c +25 -25
@@ -842,7 +842,7 @@ static const struct v4l2_queryctrl *ctrl_by_id(int id) RESOURCE_OVERLAY)static -int check_alloc_btres(struct bttv *btv, struct bttv_fh *fh, int bit) +int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) {int xbits;/* mutual exclusive resources */
@@ -935,7 +935,7 @@ disclaim_video_lines(struct bttv *btv) }static -void free_btres (struct bttv *btv,struct bttv_fh *fh,int bits) +void free_btres_lock (struct bttv *btv,struct bttv_fh *fh,int bits) {if ((fh->resources & bits) != bits) {/* trying to free ressources not allocated by us ... */
@@ -1682,7 +1682,7 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,kfree (old); }if (NULL == new) -free_btres (btv,fh,RESOURCE_OVERLAY ); +free_btres_lock (btv,fh,RESOURCE_OVERLAY );dprintk ("switch_overlay: done\n" );return retval; }
@@ -2124,7 +2124,7 @@ bttv_crop_adjust (struct bttv_crop * c,also adjust the current cropping parameters to get closer to the desired image size. */ static int -limit_scaled_size (struct bttv_fh * fh, +limit_scaled_size_lock (struct bttv_fh * fh, __s32 * width, __s32 * height, enum v4l2_field field,
@@ -2238,7 +2238,7 @@ limit_scaled_size (struct bttv_fh * fh,may also adjust the current cropping parameters to get closer to the desired window size. */ static int -verify_window (struct bttv_fh * fh, +verify_window_lock (struct bttv_fh * fh,struct v4l2_window * win,int adjust_size,int adjust_crop)
@@ -2292,7 +2292,7 @@ verify_window (struct bttv_fh * fh, win->w.width -= win->w.left & ~width_mask; win->w.left = (win->w.left - width_mask -1 ) & width_mask; - rc =limit_scaled_size (fh, &win->w.width, &win->w.height, + rc =limit_scaled_size_lock (fh, &win->w.width, &win->w.height, field, width_mask,/* width_bias: round down */ 0 , adjust_size, adjust_crop);
@@ -2303,7 +2303,7 @@ verify_window (struct bttv_fh * fh,return 0 ; } -static int setup_window (struct bttv_fh *fh,struct bttv *btv, +static int setup_window_lock (struct bttv_fh *fh,struct bttv *btv,struct v4l2_window *win,int fixup) {struct v4l2_clip *clips =NULL ;
@@ -2313,7 +2313,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,return -EINVAL ;if (!(fh->ovfmt->flags &FORMAT_FLAGS_PACKED ))return -EINVAL ; - retval =verify_window (fh, win, + retval =verify_window_lock (fh, win,/* adjust_size */ fixup,/* adjust_crop */ fixup);if (0 != retval)
@@ -2516,7 +2516,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, width = f->fmt.pix.width; height = f->fmt.pix.height; - rc = limit_scaled_size(fh, &width, &height, field, + rc = limit_scaled_size_lock(fh, &width, &height, field, /* width_mask: 4 pixels */ ~3, /* width_bias: nearest */ 2, /* adjust_size */ 1,
@@ -2536,7 +2536,7 @@ static int bttv_try_fmt_vid_overlay(struct file *file, void *priv, {struct bttv_fh *fh = priv; -return verify_window (fh, &f->fmt.win, +return verify_window_lock (fh, &f->fmt.win,/* adjust_size */ 1 ,/* adjust_crop */ 0 ); }
@@ -2563,7 +2563,7 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv, height = f->fmt.pix.height; field = f->fmt.pix.field; - retval = limit_scaled_size(fh, &width, &height, f->fmt.pix.field, + retval = limit_scaled_size_lock(fh, &width, &height, f->fmt.pix.field, /* width_mask: 4 pixels */ ~3, /* width_bias: nearest */ 2, /* adjust_size */ 1,
@@ -2601,7 +2601,7 @@ static int bttv_s_fmt_vid_overlay(struct file *file, void *priv,return -EINVAL ; } -return setup_window (fh, btv, &f->fmt.win,1 ); +return setup_window_lock (fh, btv, &f->fmt.win,1 ); }#ifdef CONFIG_VIDEO_V4L1_COMPAT
@@ -2742,7 +2742,7 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on) } } -if (!check_alloc_btres (btv, fh,RESOURCE_OVERLAY )) +if (!check_alloc_btres_lock (btv, fh,RESOURCE_OVERLAY ))return -EBUSY ;mutex_lock (&fh->cap.vb_lock);
@@ -2785,7 +2785,7 @@ static int bttv_s_fbuf(struct file *file, void *f,__s32 width = fb->fmt.width;__s32 height = fb->fmt.height; - retval = limit_scaled_size(fh, &width, &height, + retval = limit_scaled_size_lock(fh, &width, &height, V4L2_FIELD_INTERLACED, /* width_mask */ ~3, /* width_bias */ 2,
@@ -2852,7 +2852,7 @@ static int bttv_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)struct bttv *btv = fh->btv;int res =bttv_resource (fh); -if (!check_alloc_btres (btv, fh, res)) +if (!check_alloc_btres_lock (btv, fh, res))return -EBUSY ;return videobuf_qbuf (bttv_queue (fh), b);
@@ -2872,7 +2872,7 @@ static int bttv_streamon(struct file *file, void *priv,struct bttv *btv = fh->btv;int res =bttv_resource (fh); -if (!check_alloc_btres (btv, fh, res)) +if (!check_alloc_btres_lock (btv, fh, res))return -EBUSY ;return videobuf_streamon (bttv_queue (fh)); }
@@ -2890,7 +2890,7 @@ static int bttv_streamoff(struct file *file, void *priv, retval =videobuf_streamoff (bttv_queue (fh));if (retval <0 )return retval; -free_btres (btv, fh, res); +free_btres_lock (btv, fh, res);return 0 ; }
@@ -3030,7 +3030,7 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)/* Make sure tvnorm, vbi_end and the current cropping parameters remain consistent until we're done. Note -read() may change vbi_end in check_alloc_btres(). */ +read() may change vbi_end in check_alloc_btres_lock(). */ mutex_lock (&btv->lock); retval = -EBUSY ;
@@ -3128,17 +3128,17 @@ static ssize_t bttv_read(struct file *file, char __user *data,switch (fh->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE : -if (!check_alloc_btres (fh->btv, fh,RESOURCE_VIDEO_READ )) { +if (!check_alloc_btres_lock (fh->btv, fh,RESOURCE_VIDEO_READ )) {/* VIDEO_READ in use by another fh, or VIDEO_STREAM by any fh. */ return -EBUSY ; } retval =videobuf_read_one (&fh->cap, data, count, ppos, file->f_flags &O_NONBLOCK ); -free_btres (fh->btv, fh,RESOURCE_VIDEO_READ ); +free_btres_lock (fh->btv, fh,RESOURCE_VIDEO_READ );break ;case V4L2_BUF_TYPE_VBI_CAPTURE : -if (!check_alloc_btres (fh->btv,fh,RESOURCE_VBI )) +if (!check_alloc_btres_lock (fh->btv,fh,RESOURCE_VBI ))return -EBUSY ; retval =videobuf_read_stream (&fh->vbi, data, count, ppos,1 , file->f_flags &O_NONBLOCK );
@@ -3157,7 +3157,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)unsigned int rc =POLLERR ;if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { -if (!check_alloc_btres (fh->btv,fh,RESOURCE_VBI )) +if (!check_alloc_btres_lock (fh->btv,fh,RESOURCE_VBI ))return POLLERR ;return videobuf_poll_stream (file, &fh->vbi, wait); }
@@ -3288,20 +3288,20 @@ static int bttv_release(struct file *file)/* stop video capture */ if (check_btres (fh,RESOURCE_VIDEO_STREAM )) {videobuf_streamoff (&fh->cap); -free_btres (btv,fh,RESOURCE_VIDEO_STREAM ); +free_btres_lock (btv,fh,RESOURCE_VIDEO_STREAM ); }if (fh->cap.read_buf) {buffer_release (&fh->cap,fh->cap.read_buf);kfree (fh->cap.read_buf); }if (check_btres (fh,RESOURCE_VIDEO_READ )) { -free_btres (btv, fh,RESOURCE_VIDEO_READ ); +free_btres_lock (btv, fh,RESOURCE_VIDEO_READ ); }/* stop vbi capture */ if (check_btres (fh,RESOURCE_VBI )) {videobuf_stop (&fh->vbi); -free_btres (btv,fh,RESOURCE_VBI ); +free_btres_lock (btv,fh,RESOURCE_VBI ); }/* free stuff */
Signature · 1 line
1.7.1
PATCH 4/8 V4L/DVB: bttv: fix driver lock and remove explicit calls to BKL
In reply to a message not in the archivedrivers/media/video/bt8xx/bttv-driver.c +145 -60
@@ -1859,21 +1859,25 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id)unsigned int i;int err; +mutex_lock (&btv->lock); err =v4l2_prio_check (&btv->prio, fh->prio); -if (0 != err) -return err; +if (err) + goto err;for (i =0 ; i <BTTV_TVNORMS ; i++)if (*id & bttv_tvnorms[i].v4l2_id)break ; -if (i ==BTTV_TVNORMS ) -return -EINVAL ; +if (i ==BTTV_TVNORMS ) { + err = -EINVAL ; + goto err; + } -mutex_lock (&btv->lock);set_tvnorm (btv, i); + +err:mutex_unlock (&btv->lock); -return 0 ; +return err; }static int bttv_querystd (struct file *file,void *f,v4l2_std_id *id)
@@ -1893,10 +1897,13 @@ static int bttv_enum_input(struct file *file, void *priv, {struct bttv_fh *fh = priv;struct bttv *btv = fh->btv; -int n; +int rc =0 ; -if (i->index >= bttv_tvcards[btv->c.type].video_inputs) -return -EINVAL ; +mutex_lock (&btv->lock); +if (i->index >= bttv_tvcards[btv->c.type].video_inputs) { + rc = -EINVAL ; + goto err; + } i->type =V4L2_INPUT_TYPE_CAMERA ; i->audioset =1 ;
@@ -1919,10 +1926,12 @@ static int bttv_enum_input(struct file *file, void *priv, i->status |=V4L2_IN_ST_NO_H_LOCK ; } -for (n =0 ; n <BTTV_TVNORMS ; n++) - i->std |= bttv_tvnorms[n].v4l2_id; + i->std =BTTV_NORMS ; -return 0 ; +err: +mutex_unlock (&btv->lock); + +return rc; }static int bttv_g_input (struct file *file,void *priv,unsigned int *i)
@@ -1930,7 +1939,10 @@ static int bttv_g_input(struct file *file, void *priv, unsigned int *i)struct bttv_fh *fh = priv;struct bttv *btv = fh->btv; +mutex_lock (&btv->lock); *i = btv->input; +mutex_unlock (&btv->lock); +return 0 ; }
@@ -1941,15 +1953,19 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i)int err; - err =v4l2_prio_check (&btv->prio, fh->prio); -if (0 != err) -return err; - -if (i > bttv_tvcards[btv->c.type].video_inputs) -return -EINVAL ; -mutex_lock (&btv->lock); + err =v4l2_prio_check (&btv->prio, fh->prio); +if (unlikely (err)) + goto err; + +if (i > bttv_tvcards[btv->c.type].video_inputs) { + err = -EINVAL ; + goto err; + } +set_input (btv, i, btv->tvnorm); + +err:mutex_unlock (&btv->lock);return 0 ; }
@@ -1961,22 +1977,25 @@ static int bttv_s_tuner(struct file *file, void *priv,struct bttv *btv = fh->btv;int err; - err =v4l2_prio_check (&btv->prio, fh->prio); -if (0 != err) -return err; - -if (btv->tuner_type ==TUNER_ABSENT ) -return -EINVAL ; - -if (0 != t->index) +if (unlikely (0 != t->index))return -EINVAL ;mutex_lock (&btv->lock); +if (unlikely (btv->tuner_type ==TUNER_ABSENT )) { + err = -EINVAL ; + goto err; + } + + err =v4l2_prio_check (&btv->prio, fh->prio); +if (unlikely (err)) + goto err; +bttv_call_all (btv, tuner, s_tuner, t);if (btv->audio_mode_gpio) btv->audio_mode_gpio (btv, t,1 ); +err:mutex_unlock (&btv->lock);return 0 ;
@@ -1988,8 +2007,10 @@ static int bttv_g_frequency(struct file *file, void *priv,struct bttv_fh *fh = priv;struct bttv *btv = fh->btv; +mutex_lock (&btv->lock); f->type = btv->radio_user ?V4L2_TUNER_RADIO :V4L2_TUNER_ANALOG_TV ; f->frequency = btv->freq; +mutex_unlock (&btv->lock);return 0 ; }
@@ -2001,21 +2022,26 @@ static int bttv_s_frequency(struct file *file, void *priv,struct bttv *btv = fh->btv;int err; - err =v4l2_prio_check (&btv->prio, fh->prio); -if (0 != err) -return err; -if (unlikely (f->tuner !=0 ))return -EINVAL ; + +mutex_lock (&btv->lock); + err =v4l2_prio_check (&btv->prio, fh->prio); +if (unlikely (err)) + goto err; +if (unlikely (f->type != (btv->radio_user - ?V4L2_TUNER_RADIO :V4L2_TUNER_ANALOG_TV ))) -return -EINVAL ; -mutex_lock (&btv->lock); + ?V4L2_TUNER_RADIO :V4L2_TUNER_ANALOG_TV ))) { + err = -EINVAL ; + goto err; + } btv->freq = f->frequency;bttv_call_all (btv, tuner, s_frequency, f);if (btv->has_matchbox && btv->radio_user)tea5757_set_freq (btv, btv->freq); +err:mutex_unlock (&btv->lock); +return 0 ; }
@@ -2257,7 +2283,9 @@ verify_window_lock (struct bttv_fh * fh,if (V4L2_FIELD_ANY == field) {__s32 height2; +mutex_lock (&fh->btv->lock); height2 = fh->btv->crop[!!fh->do_crop].rect.height >>1 ; +mutex_unlock (&fh->btv->lock); field = (win->w.height > height2) ?V4L2_FIELD_INTERLACED :V4L2_FIELD_TOP ;
@@ -2332,6 +2360,8 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv,return -EFAULT ; } } + +mutex_lock (&fh->cap.vb_lock);/* clip against screen */ if (NULL != btv->fbuf.base) n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height,
@@ -2354,7 +2384,6 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv,BUG (); } -mutex_lock (&fh->cap.vb_lock);kfree (fh->ov.clips); fh->ov.clips = clips; fh->ov.nclips = n;
@@ -2362,6 +2391,14 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv, fh->ov.w = win->w; fh->ov.field = win->field; fh->ov.setup_ok =1 ; + +/* +* FIXME: btv is protected by btv->lock mutex, while btv->init +* is protected by fh->cap.vb_lock. This seems to open the +* possibility for some race situations. Maybe the better would +* be to unify those locks or to use another way to store the +* init values that will be consumed by videobuf callbacks +*/ btv->init.ov.w.width = win->w.width; btv->init.ov.w.height = win->w.height; btv->init.ov.field = win->field;
@@ -2490,7 +2527,9 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv,if (V4L2_FIELD_ANY == field) {__s32 height2; +mutex_lock (&btv->lock); height2 = btv->crop[!!fh->do_crop].rect.height >>1 ; +mutex_unlock (&btv->lock); field = (f->fmt.pix.height > height2) ?V4L2_FIELD_INTERLACED :V4L2_FIELD_BOTTOM ;
@@ -2651,11 +2690,15 @@ static int bttv_querycap(struct file *file, void *priv,V4L2_CAP_VBI_CAPTURE |V4L2_CAP_READWRITE |V4L2_CAP_STREAMING ; -if (btv->has_saa6588) - cap->capabilities |=V4L2_CAP_RDS_CAPTURE ;if (no_overlay <=0 ) cap->capabilities |=V4L2_CAP_VIDEO_OVERLAY ; +/* +* No need to lock here: those vars are initialized during board +* probe and remains untouched during the rest of the driver lifecycle +*/ +if (btv->has_saa6588) + cap->capabilities |=V4L2_CAP_RDS_CAPTURE ;if (btv->tuner_type !=TUNER_ABSENT ) cap->capabilities |=V4L2_CAP_TUNER ;return 0 ;
@@ -2730,16 +2773,22 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on)struct bttv_fh *fh = f;struct bttv *btv = fh->btv;struct bttv_buffer *new; -int retval; +int retval =0 ;if (on) { +mutex_lock (&fh->cap.vb_lock);/* verify args */ -if (NULL == btv->fbuf.base) +if (unlikely (!btv->fbuf.base)) { +mutex_unlock (&fh->cap.vb_lock);return -EINVAL ; -if (!fh->ov.setup_ok) { + } +if (unlikely (!fh->ov.setup_ok)) {dprintk ("bttv%d: overlay: !setup_ok\n" , btv->c.nr); -return -EINVAL ; + retval = -EINVAL ; } +if (retval) +return retval; +mutex_unlock (&fh->cap.vb_lock); }if (!check_alloc_btres_lock (btv, fh,RESOURCE_OVERLAY ))
@@ -2907,6 +2956,7 @@ static int bttv_queryctrl(struct file *file, void *priv, c->id >= V4L2_CID_PRIVATE_LASTP1))return -EINVAL ; +mutex_lock (&btv->lock);if (!btv->volume_gpio && (c->id ==V4L2_CID_AUDIO_VOLUME )) *c = no_ctl;else {
@@ -2914,6 +2964,7 @@ static int bttv_queryctrl(struct file *file, void *priv, *c = (NULL != ctrl) ? *ctrl : no_ctl; } +mutex_unlock (&btv->lock);return 0 ; }
@@ -2924,8 +2975,11 @@ static int bttv_g_parm(struct file *file, void *f,struct bttv_fh *fh = f;struct bttv *btv = fh->btv; +mutex_lock (&btv->lock);v4l2_video_std_frame_period (bttv_tvnorms[btv->tvnorm].v4l2_id, &parm->parm.capture.timeperframe); +mutex_unlock (&btv->lock); +return 0 ; }
@@ -2961,7 +3015,9 @@ static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p)struct bttv_fh *fh = f;struct bttv *btv = fh->btv; +mutex_lock (&btv->lock); *p =v4l2_prio_max (&btv->prio); +mutex_unlock (&btv->lock);return 0 ; }
@@ -2971,8 +3027,13 @@ static int bttv_s_priority(struct file *file, void *f, {struct bttv_fh *fh = f;struct bttv *btv = fh->btv; +int rc; -return v4l2_prio_change (&btv->prio, &fh->prio, prio); +mutex_lock (&btv->lock); + rc =v4l2_prio_change (&btv->prio, &fh->prio, prio); +mutex_unlock (&btv->lock); + +return rc; } static int bttv_cropcap(struct file *file, void *priv,
@@ -2985,7 +3046,9 @@ static int bttv_cropcap(struct file *file, void *priv, cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) return -EINVAL; +mutex_lock (&btv->lock); *cap = bttv_tvnorms[btv->tvnorm].cropcap; +mutex_unlock (&btv->lock);return 0 ; }
@@ -3003,7 +3066,9 @@ static int bttv_g_crop(struct file *file, void *f, struct v4l2_crop *crop)inconsistent with fh->width or fh->height and apps do not expect a change here. */ +mutex_lock (&btv->lock); crop->c = btv->crop[!!fh->do_crop].rect; +mutex_unlock (&btv->lock);return 0 ; }
@@ -3024,14 +3089,15 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)return -EINVAL ; - retval =v4l2_prio_check (&btv->prio, fh->prio); -if (0 != retval) -return retval; -/* Make sure tvnorm, vbi_end and the current cropping parameters remain consistent until we're done. Note read() may change vbi_end in check_alloc_btres_lock(). */ mutex_lock (&btv->lock); + retval =v4l2_prio_check (&btv->prio, fh->prio); +if (0 != retval) { +mutex_unlock (&btv->lock); +return retval; + } retval = -EBUSY ;
@@ -3221,21 +3287,32 @@ static int bttv_open(struct file *file)return -ENODEV ; } -lock_kernel (); -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) { -unlock_kernel (); + fh =kmalloc (sizeof (*fh),GFP_KERNEL ); +if (unlikely (!fh))return -ENOMEM ; - } file->private_data = fh; + +/* +* btv is protected by btv->lock mutex, while btv->init and other +* streaming vars are protected by fh->cap.vb_lock. We need to take +* care of both locks to avoid troubles. However, vb_lock is used also +* inside videobuf, without calling buf->lock. So, it is a very bad +* idea to hold both locks at the same time. +* Let's first copy btv->init at fh, holding cap.vb_lock, and then work +* with the rest of init, holding btv->lock. +*/ +mutex_lock (&fh->cap.vb_lock); *fh = btv->init; +mutex_unlock (&fh->cap.vb_lock); + fh->type = type; fh->ov.setup_ok =0 ; + +mutex_lock (&btv->lock);v4l2_prio_open (&btv->prio, &fh->prio); videobuf_queue_sg_init(&fh->cap, &bttv_video_qops,
@@ -3272,7 +3349,7 @@ static int bttv_open(struct file *file)bttv_vbi_fmt_reset (&fh->vbi_fmt, btv->tvnorm);bttv_field_count (btv); -unlock_kernel (); +mutex_unlock (&btv->lock);return 0 ; }
@@ -3281,6 +3358,7 @@ static int bttv_release(struct file *file)struct bttv_fh *fh = file->private_data;struct bttv *btv = fh->btv; +mutex_lock (&btv->lock);/* turn off overlay */ if (check_btres (fh,RESOURCE_OVERLAY ))bttv_switch_overlay (btv,fh,NULL );
@@ -3305,8 +3383,15 @@ static int bttv_release(struct file *file) }/* free stuff */ + +/* +* videobuf uses cap.vb_lock - we should avoid holding btv->lock, +* otherwise we may have dead lock conditions +*/ +mutex_unlock (&btv->lock);videobuf_mmap_free (&fh->cap);videobuf_mmap_free (&fh->vbi); +mutex_lock (&btv->lock);v4l2_prio_close (&btv->prio, fh->prio); file->private_data =NULL ;kfree (fh);
@@ -3316,6 +3401,7 @@ static int bttv_release(struct file *file)if (!btv->users)audio_mute (btv,1 ); +mutex_unlock (&btv->lock);return 0 ; }
@@ -3412,21 +3498,19 @@ static int radio_open(struct file *file)dprintk ("bttv: open dev=%s\n" ,video_device_node_name (vdev)); -lock_kernel (); -dprintk ("bttv%d: open called (radio)\n" ,btv->c.nr);/* allocate per filehandle data */ fh =kmalloc (sizeof (*fh),GFP_KERNEL ); -if (NULL == fh) { -unlock_kernel (); +if (unlikely (!fh))return -ENOMEM ; - } file->private_data = fh; +mutex_lock (&fh->cap.vb_lock); *fh = btv->init; -v4l2_prio_open (&btv->prio, &fh->prio); +mutex_unlock (&fh->cap.vb_lock);mutex_lock (&btv->lock); +v4l2_prio_open (&btv->prio, &fh->prio); btv->radio_user++;
@@ -3434,7 +3518,6 @@ static int radio_open(struct file *file)audio_input (btv,TVAUDIO_INPUT_RADIO );mutex_unlock (&btv->lock); -unlock_kernel ();return 0 ; }
@@ -3444,6 +3527,7 @@ static int radio_release(struct file *file)struct bttv *btv = fh->btv;struct rds_command cmd; +mutex_lock (&btv->lock);v4l2_prio_close (&btv->prio, fh->prio); file->private_data =NULL ;kfree (fh);
@@ -3451,6 +3535,7 @@ static int radio_release(struct file *file) btv->radio_user--;bttv_call_all (btv, core, ioctl,RDS_CMD_CLOSE , &cmd); +mutex_unlock (&btv->lock);return 0 ; }
Signature · 1 line
1.7.1
PATCH 5/8 V4L/DVB: bttv: use unlocked ioctl
In reply to a message not in the archivedrivers/media/video/bt8xx/bttv-driver.c +7 -7
@@ -3419,13 +3419,13 @@ bttv_mmap(struct file *file, struct vm_area_struct *vma)static const struct v4l2_file_operations bttv_fops = { - .owner =THIS_MODULE , - .open = bttv_open, - .release = bttv_release, - .ioctl = video_ioctl2, - .read = bttv_read, - .mmap = bttv_mmap, - .poll = bttv_poll, + .owner =THIS_MODULE , + .open = bttv_open, + .release = bttv_release, + .unlocked_ioctl = video_ioctl2, + .read = bttv_read, + .mmap = bttv_mmap, + .poll = bttv_poll, };static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
Signature · 1 line
1.7.1
PATCH 6/8 V4L/DVB: cx88: Remove BKL
In reply to a message not in the archivedrivers/media/video/cx88/cx88-blackbird.c +8 -6
@@ -1057,7 +1057,7 @@ static int mpeg_open(struct file *file)dprintk (1 ,"%s\n" , __func__); -lock_kernel (); +mutex_lock (&dev->core->lock);/* Make sure we can acquire the hardware */ drv =cx8802_get_driver (dev,CX88_MPEG_BLACKBIRD );
@@ -1065,7 +1065,7 @@ static int mpeg_open(struct file *file) err = drv->request_acquire (drv);if (err !=0 ) {dprintk (1 ,"%s: Unable to acquire hardware, %d\n" , __func__, err); -unlock_kernel (); +mutex_unlock (&dev->core->lock);;return err; } }
@@ -1073,7 +1073,7 @@ static int mpeg_open(struct file *file)if (!atomic_read (&dev->core->mpeg_users) &&blackbird_initialize_codec (dev) <0 ) {if (drv) drv->request_release (drv); -unlock_kernel (); +mutex_unlock (&dev->core->lock);return -EINVAL ; }dprintk (1 ,"open dev=%s\n" ,video_device_node_name (vdev));
@@ -1083,7 +1083,7 @@ static int mpeg_open(struct file *file)if (NULL == fh) {if (drv) drv->request_release (drv); -unlock_kernel (); +mutex_unlock (&dev->core->lock);return -ENOMEM ; } file->private_data = fh;
@@ -1099,10 +1099,9 @@ static int mpeg_open(struct file *file)/* FIXME: locking against other video device */ cx88_set_scale (dev->core, dev->width, dev->height, fh->mpegq.field); -unlock_kernel ();atomic_inc (&dev->core->mpeg_users); - +mutex_unlock (&dev->core->lock);return 0 ; }
@@ -1120,8 +1119,11 @@ static int mpeg_release(struct file *file)videobuf_stop (&fh->mpegq);videobuf_mmap_free (&fh->mpegq); + +mutex_lock (&dev->core->lock); file->private_data =NULL ;kfree (fh); +mutex_unlock (&dev->core->lock);/* Make sure we release the hardware */ drv =cx8802_get_driver (dev,CX88_MPEG_BLACKBIRD );
drivers/media/video/cx88/cx88-video.c +8 -9
@@ -769,19 +769,14 @@ static int video_open(struct file *file)break ; } -lock_kernel (); - - core = dev->core; -dprintk (1 ,"open dev=%s radio=%d type=%s\n" ,video_device_node_name (vdev), radio, v4l2_type_names[type]);/* allocate + initialize per filehandle data */ fh =kzalloc (sizeof (*fh),GFP_KERNEL ); -if (NULL == fh) { -unlock_kernel (); +if (unlikely (!fh))return -ENOMEM ; - } + file->private_data = fh; fh->dev = dev; fh->radio = radio;
@@ -790,6 +785,9 @@ static int video_open(struct file *file) fh->height =240 ; fh->fmt =format_by_fourcc (V4L2_PIX_FMT_BGR24 ); +mutex_lock (&core->lock); + core = dev->core; + videobuf_queue_sg_init(&fh->vidq, &cx8800_video_qops, &dev->pci->dev, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
@@ -826,9 +824,9 @@ static int video_open(struct file *file) }call_all (core, tuner, s_radio); } -unlock_kernel ();atomic_inc (&core->users); +mutex_unlock (&core->lock);return 0 ; }
@@ -920,10 +918,11 @@ static int video_release(struct file *file)videobuf_mmap_free (&fh->vidq);videobuf_mmap_free (&fh->vbiq); + +mutex_lock (&dev->core->lock); file->private_data =NULL ;kfree (fh); -mutex_lock (&dev->core->lock);if (atomic_dec_and_test (&dev->core->users))call_all (dev->core, core, s_power,0 );mutex_unlock (&dev->core->lock);
Signature · 1 line
1.7.1
PATCH 8/8 V4L/DVB: Deprecate stradis driver
In reply to a message not in the archiveThe driver author seems to not worked on this driver since its conversion from 2.2 to 2.4. Nobody is known to have a stradis hardware for testing. As it still uses V4L1 API, BKL and probably some other old stuff, someone would need to work on it to preserve the driver. Instead of investing time and efforts to keep porting it to work with new API's, it seems better to just drop the driver.
So, let's move it to drivers/staging and label it to die at 2.6.38, if nobody cares enough to port parallel port support to gspca or to create a new driver that uses the same gspca-cpia sub-driver.
delete mode 100644 drivers/media/video/stradis.c create mode 100644 drivers/staging/stradis/Kconfig create mode 100644 drivers/staging/stradis/Makefile create mode 100644 drivers/staging/stradis/TODO create mode 100644 drivers/staging/stradis/stradis.c
Documentation/feature-removal-schedule.txt +2 -2
@@ -118,8 +118,8 @@ Who: Mauro Carvalho Chehab <[email protected]> What: Video4Linux obsolete drivers using V4L1 API When: kernel 2.6.38 -Files: drivers/staging/cpia/* -Check: drivers/staging/cpia/cpia.c +Files: drivers/staging/cpia/* drivers/staging/stradis/* +Check: drivers/staging/cpia/cpia.c drivers/staging/stradis/stradis.c Why: There are some drivers still using V4L1 API, despite all efforts we've done to migrate. Those drivers are for obsolete hardware that the old maintainer didn't care (or not have the hardware anymore), and that no other developer
drivers/media/video/Kconfig +0 -8
@@ -629,14 +629,6 @@ config VIDEO_VINO Say Y here to build in support for the Vino video input system found on SGI Indy machines. -config VIDEO_STRADIS - tristate "Stradis 4:2:2 MPEG-2 video driver (EXPERIMENTAL)" - depends on EXPERIMENTAL && PCI && VIDEO_V4L1 && VIRT_TO_BUS - help - Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video - driver for PCI. There is a product page at - <http://www.stradis.com/>. - source "drivers/media/video/zoran/Kconfig" config VIDEO_MEYE
drivers/media/video/Makefile +0 -1
@@ -93,7 +93,6 @@ obj-$(CONFIG_VIDEO_BWQCAM) += bw-qcam.o obj-$(CONFIG_VIDEO_W9966) += w9966.o obj-$(CONFIG_VIDEO_PMS) += pms.o obj-$(CONFIG_VIDEO_VINO) += vino.o -obj-$(CONFIG_VIDEO_STRADIS) += stradis.o obj-$(CONFIG_VIDEO_MEYE) += meye.o obj-$(CONFIG_VIDEO_SAA7134) += saa7134/ obj-$(CONFIG_VIDEO_CX88) += cx88/
drivers/media/video/stradis.c deleted +0 -2213
2,213 lines not on this page · raw message
drivers/staging/stradis/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config VIDEO_STRADIS + tristate "Stradis 4:2:2 MPEG-2 video driver (DEPRECATED)" + depends on EXPERIMENTAL && PCI && VIDEO_V4L1 && VIRT_TO_BUS + help + Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video + driver for PCI. There is a product page at + <http://www.stradis.com/>.
drivers/staging/stradis/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_VIDEO_STRADIS) += stradis.o + +EXTRA_CFLAGS += -Idrivers/media/video
drivers/staging/stradis/TODO new file +6 -0
@@ -0,0 +1,6 @@ +This is an obsolete driver for ancient stradis hardware. +We couldn't find anyone with this hardware in order to port it to use V4L2. + +If nobody take care on it, the driver will be removed for 2.6.38. + +Please send patches to [email protected]
drivers/staging/stradis/stradis.c new file +2213 -0
740 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.