aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pwc
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2011-06-25 16:39:19 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-07-27 16:53:43 -0400
commitb824bb4b12548fedd622686d443310d574eb084e (patch)
tree09b71717e080d9809a73e4a198d15a7a892f0fb6 /drivers/media/video/pwc
parent1a4ede65f30315a31cb9b239bec0d4bb32834691 (diff)
[media] pwc: Get rid of error_status and unplugged variables
Having 2 ways of tracking disconnection is too much, remove both and instead simply set pdev->udev to NULL on disconnect. Also check for pdev->udev being NULL in all possible entry paths. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/pwc')
-rw-r--r--drivers/media/video/pwc/pwc-if.c38
-rw-r--r--drivers/media/video/pwc/pwc-v4l.c24
-rw-r--r--drivers/media/video/pwc/pwc.h2
3 files changed, 41 insertions, 23 deletions
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 907db23fdb5d..6bff33b357b9 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -570,14 +570,7 @@ static void pwc_isoc_cleanup(struct pwc_device *pdev)
570 570
571 pwc_iso_stop(pdev); 571 pwc_iso_stop(pdev);
572 pwc_iso_free(pdev); 572 pwc_iso_free(pdev);
573 573 usb_set_interface(pdev->udev, 0, 0);
574 /* Stop camera, but only if we are sure the camera is still there (unplug
575 is signalled by EPIPE)
576 */
577 if (pdev->error_status != EPIPE) {
578 PWC_DEBUG_OPEN("Setting alternate interface 0.\n");
579 usb_set_interface(pdev->udev, 0, 0);
580 }
581 574
582 pdev->iso_init = 0; 575 pdev->iso_init = 0;
583 PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n"); 576 PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n");
@@ -719,6 +712,9 @@ static int pwc_video_open(struct file *file)
719 PWC_DEBUG_OPEN(">> video_open called(vdev = 0x%p).\n", vdev); 712 PWC_DEBUG_OPEN(">> video_open called(vdev = 0x%p).\n", vdev);
720 713
721 pdev = video_get_drvdata(vdev); 714 pdev = video_get_drvdata(vdev);
715 if (!pdev->udev)
716 return -ENODEV;
717
722 if (pdev->vopen) { 718 if (pdev->vopen) {
723 PWC_DEBUG_OPEN("I'm busy, someone is using the device.\n"); 719 PWC_DEBUG_OPEN("I'm busy, someone is using the device.\n");
724 return -EBUSY; 720 return -EBUSY;
@@ -760,7 +756,6 @@ static int pwc_video_open(struct file *file)
760 756
761 /* Reset buffers & parameters */ 757 /* Reset buffers & parameters */
762 pdev->visoc_errors = 0; 758 pdev->visoc_errors = 0;
763 pdev->error_status = 0;
764 pwc_construct(pdev); /* set min/max sizes correct */ 759 pwc_construct(pdev); /* set min/max sizes correct */
765 760
766 /* Set some defaults */ 761 /* Set some defaults */
@@ -837,7 +832,7 @@ static int pwc_video_close(struct file *file)
837 pwc_free_buffers(pdev); 832 pwc_free_buffers(pdev);
838 833
839 /* Turn off LEDS and power down camera, but only when not unplugged */ 834 /* Turn off LEDS and power down camera, but only when not unplugged */
840 if (!pdev->unplugged) { 835 if (pdev->udev) {
841 /* Turn LEDs off */ 836 /* Turn LEDs off */
842 if (pwc_set_leds(pdev, 0, 0) < 0) 837 if (pwc_set_leds(pdev, 0, 0) < 0)
843 PWC_DEBUG_MODULE("Failed to set LED on/off time.\n"); 838 PWC_DEBUG_MODULE("Failed to set LED on/off time.\n");
@@ -859,8 +854,8 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
859 struct video_device *vdev = file->private_data; 854 struct video_device *vdev = file->private_data;
860 struct pwc_device *pdev = video_get_drvdata(vdev); 855 struct pwc_device *pdev = video_get_drvdata(vdev);
861 856
862 if (pdev->error_status) 857 if (!pdev->udev)
863 return -pdev->error_status; 858 return -ENODEV;
864 859
865 return vb2_read(&pdev->vb_queue, buf, count, ppos, 860 return vb2_read(&pdev->vb_queue, buf, count, ppos,
866 file->f_flags & O_NONBLOCK); 861 file->f_flags & O_NONBLOCK);
@@ -871,7 +866,7 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
871 struct video_device *vdev = file->private_data; 866 struct video_device *vdev = file->private_data;
872 struct pwc_device *pdev = video_get_drvdata(vdev); 867 struct pwc_device *pdev = video_get_drvdata(vdev);
873 868
874 if (pdev->error_status) 869 if (!pdev->udev)
875 return POLL_ERR; 870 return POLL_ERR;
876 871
877 return vb2_poll(&pdev->vb_queue, file, wait); 872 return vb2_poll(&pdev->vb_queue, file, wait);
@@ -923,8 +918,8 @@ static int buffer_prepare(struct vb2_buffer *vb)
923 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue); 918 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
924 919
925 /* Don't allow queing new buffers after device disconnection */ 920 /* Don't allow queing new buffers after device disconnection */
926 if (pdev->error_status) 921 if (!pdev->udev)
927 return -pdev->error_status; 922 return -ENODEV;
928 923
929 return 0; 924 return 0;
930} 925}
@@ -964,6 +959,9 @@ static int start_streaming(struct vb2_queue *vq)
964{ 959{
965 struct pwc_device *pdev = vb2_get_drv_priv(vq); 960 struct pwc_device *pdev = vb2_get_drv_priv(vq);
966 961
962 if (!pdev->udev)
963 return -ENODEV;
964
967 return pwc_isoc_init(pdev); 965 return pwc_isoc_init(pdev);
968} 966}
969 967
@@ -971,7 +969,8 @@ static int stop_streaming(struct vb2_queue *vq)
971{ 969{
972 struct pwc_device *pdev = vb2_get_drv_priv(vq); 970 struct pwc_device *pdev = vb2_get_drv_priv(vq);
973 971
974 pwc_isoc_cleanup(pdev); 972 if (pdev->udev)
973 pwc_isoc_cleanup(pdev);
975 pwc_cleanup_queued_bufs(pdev); 974 pwc_cleanup_queued_bufs(pdev);
976 975
977 return 0; 976 return 0;
@@ -1389,15 +1388,12 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
1389 struct pwc_device *pdev = usb_get_intfdata(intf); 1388 struct pwc_device *pdev = usb_get_intfdata(intf);
1390 1389
1391 mutex_lock(&pdev->modlock); 1390 mutex_lock(&pdev->modlock);
1392 usb_set_intfdata (intf, NULL);
1393
1394 /* We got unplugged; this is signalled by an EPIPE error code */
1395 pdev->error_status = EPIPE;
1396 pdev->unplugged = 1;
1397 1391
1392 usb_set_intfdata(intf, NULL);
1398 /* No need to keep the urbs around after disconnection */ 1393 /* No need to keep the urbs around after disconnection */
1399 pwc_isoc_cleanup(pdev); 1394 pwc_isoc_cleanup(pdev);
1400 pwc_cleanup_queued_bufs(pdev); 1395 pwc_cleanup_queued_bufs(pdev);
1396 pdev->udev = NULL;
1401 1397
1402 mutex_unlock(&pdev->modlock); 1398 mutex_unlock(&pdev->modlock);
1403 1399
diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index cda38837adcd..8bd0a681990d 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -288,6 +288,9 @@ static int pwc_vidioc_set_fmt(struct pwc_device *pdev, struct v4l2_format *f)
288{ 288{
289 int ret, fps, snapshot, compression, pixelformat; 289 int ret, fps, snapshot, compression, pixelformat;
290 290
291 if (!pdev->udev)
292 return -ENODEV;
293
291 ret = pwc_vidioc_try_fmt(pdev, f); 294 ret = pwc_vidioc_try_fmt(pdev, f);
292 if (ret<0) 295 if (ret<0)
293 return ret; 296 return ret;
@@ -346,6 +349,9 @@ static int pwc_querycap(struct file *file, void *fh, struct v4l2_capability *cap
346 struct video_device *vdev = video_devdata(file); 349 struct video_device *vdev = video_devdata(file);
347 struct pwc_device *pdev = video_drvdata(file); 350 struct pwc_device *pdev = video_drvdata(file);
348 351
352 if (!pdev->udev)
353 return -ENODEV;
354
349 strcpy(cap->driver, PWC_NAME); 355 strcpy(cap->driver, PWC_NAME);
350 strlcpy(cap->card, vdev->name, sizeof(cap->card)); 356 strlcpy(cap->card, vdev->name, sizeof(cap->card));
351 usb_make_path(pdev->udev, cap->bus_info, sizeof(cap->bus_info)); 357 usb_make_path(pdev->udev, cap->bus_info, sizeof(cap->bus_info));
@@ -414,6 +420,9 @@ static int pwc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
414 struct pwc_device *pdev = video_drvdata(file); 420 struct pwc_device *pdev = video_drvdata(file);
415 int ret; 421 int ret;
416 422
423 if (!pdev->udev)
424 return -ENODEV;
425
417 switch (c->id) { 426 switch (c->id) {
418 case V4L2_CID_BRIGHTNESS: 427 case V4L2_CID_BRIGHTNESS:
419 c->value = pwc_get_brightness(pdev); 428 c->value = pwc_get_brightness(pdev);
@@ -517,6 +526,9 @@ static int pwc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
517 struct pwc_device *pdev = video_drvdata(file); 526 struct pwc_device *pdev = video_drvdata(file);
518 int ret; 527 int ret;
519 528
529 if (!pdev->udev)
530 return -ENODEV;
531
520 switch (c->id) { 532 switch (c->id) {
521 case V4L2_CID_BRIGHTNESS: 533 case V4L2_CID_BRIGHTNESS:
522 c->value <<= 9; 534 c->value <<= 9;
@@ -692,6 +704,9 @@ static int pwc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
692{ 704{
693 struct pwc_device *pdev = video_drvdata(file); 705 struct pwc_device *pdev = video_drvdata(file);
694 706
707 if (!pdev->udev)
708 return -ENODEV;
709
695 return vb2_qbuf(&pdev->vb_queue, buf); 710 return vb2_qbuf(&pdev->vb_queue, buf);
696} 711}
697 712
@@ -699,6 +714,9 @@ static int pwc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
699{ 714{
700 struct pwc_device *pdev = video_drvdata(file); 715 struct pwc_device *pdev = video_drvdata(file);
701 716
717 if (!pdev->udev)
718 return -ENODEV;
719
702 return vb2_dqbuf(&pdev->vb_queue, buf, file->f_flags & O_NONBLOCK); 720 return vb2_dqbuf(&pdev->vb_queue, buf, file->f_flags & O_NONBLOCK);
703} 721}
704 722
@@ -706,6 +724,9 @@ static int pwc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
706{ 724{
707 struct pwc_device *pdev = video_drvdata(file); 725 struct pwc_device *pdev = video_drvdata(file);
708 726
727 if (!pdev->udev)
728 return -ENODEV;
729
709 return vb2_streamon(&pdev->vb_queue, i); 730 return vb2_streamon(&pdev->vb_queue, i);
710} 731}
711 732
@@ -713,6 +734,9 @@ static int pwc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
713{ 734{
714 struct pwc_device *pdev = video_drvdata(file); 735 struct pwc_device *pdev = video_drvdata(file);
715 736
737 if (!pdev->udev)
738 return -ENODEV;
739
716 return vb2_streamoff(&pdev->vb_queue, i); 740 return vb2_streamoff(&pdev->vb_queue, i);
717} 741}
718 742
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index cfe82319f343..13b85246a261 100644
--- a/drivers/media/video/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -161,7 +161,6 @@ struct pwc_device
161 int release; /* release number */ 161 int release; /* release number */
162 int features; /* feature bits */ 162 int features; /* feature bits */
163 char serial[30]; /* serial number (string) */ 163 char serial[30]; /* serial number (string) */
164 int error_status; /* set when something goes wrong */
165 int usb_init; /* set when the cam has been initialized */ 164 int usb_init; /* set when the cam has been initialized */
166 165
167 /*** Video data ***/ 166 /*** Video data ***/
@@ -180,7 +179,6 @@ struct pwc_device
180 char vsnapshot; /* snapshot mode */ 179 char vsnapshot; /* snapshot mode */
181 char vsync; /* used by isoc handler */ 180 char vsync; /* used by isoc handler */
182 char vmirror; /* for ToUCaM series */ 181 char vmirror; /* for ToUCaM series */
183 char unplugged;
184 182
185 int cmd_len; 183 int cmd_len;
186 unsigned char cmd_buf[13]; 184 unsigned char cmd_buf[13];