aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/cx231xx
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2012-01-10 06:48:50 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-01-10 19:35:31 -0500
commit990862a2f024296f27460306393de8f0cdab8997 (patch)
treee8bc467d130a57dd03428010db57794b49f0b964 /drivers/media/video/cx231xx
parentdb702a7af6c85d94ff32b6110b3646180f93f086 (diff)
[media] cx231xx: fix device disconnect checks
The driver were using DEV_MISCONFIGURED on some places, and DEV_DISCONNECTED on others. In a matter of fact, DEV_MISCONFIGURED were set only during the usb disconnect callback, with was confusing. Also, the alsa driver never checks if the device is present, before doing some dangerous things. Remove DEV_MISCONFIGURED, replacing it by DEV_DISCONNECTED. Also, fixes the other usecases for DEV_DISCONNECTED. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/cx231xx')
-rw-r--r--drivers/media/video/cx231xx/cx231xx-audio.c20
-rw-r--r--drivers/media/video/cx231xx/cx231xx-cards.c5
-rw-r--r--drivers/media/video/cx231xx/cx231xx-dvb.c4
-rw-r--r--drivers/media/video/cx231xx/cx231xx-vbi.c2
-rw-r--r--drivers/media/video/cx231xx/cx231xx-video.c14
-rw-r--r--drivers/media/video/cx231xx/cx231xx.h1
6 files changed, 29 insertions, 17 deletions
diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
index 30d13c15739a..e5742a0e19a0 100644
--- a/drivers/media/video/cx231xx/cx231xx-audio.c
+++ b/drivers/media/video/cx231xx/cx231xx-audio.c
@@ -111,6 +111,9 @@ static void cx231xx_audio_isocirq(struct urb *urb)
111 struct snd_pcm_substream *substream; 111 struct snd_pcm_substream *substream;
112 struct snd_pcm_runtime *runtime; 112 struct snd_pcm_runtime *runtime;
113 113
114 if (dev->state & DEV_DISCONNECTED)
115 return;
116
114 switch (urb->status) { 117 switch (urb->status) {
115 case 0: /* success */ 118 case 0: /* success */
116 case -ETIMEDOUT: /* NAK */ 119 case -ETIMEDOUT: /* NAK */
@@ -196,6 +199,9 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
196 struct snd_pcm_substream *substream; 199 struct snd_pcm_substream *substream;
197 struct snd_pcm_runtime *runtime; 200 struct snd_pcm_runtime *runtime;
198 201
202 if (dev->state & DEV_DISCONNECTED)
203 return;
204
199 switch (urb->status) { 205 switch (urb->status) {
200 case 0: /* success */ 206 case 0: /* success */
201 case -ETIMEDOUT: /* NAK */ 207 case -ETIMEDOUT: /* NAK */
@@ -273,6 +279,9 @@ static int cx231xx_init_audio_isoc(struct cx231xx *dev)
273 279
274 cx231xx_info("%s: Starting ISO AUDIO transfers\n", __func__); 280 cx231xx_info("%s: Starting ISO AUDIO transfers\n", __func__);
275 281
282 if (dev->state & DEV_DISCONNECTED)
283 return -ENODEV;
284
276 sb_size = CX231XX_ISO_NUM_AUDIO_PACKETS * dev->adev.max_pkt_size; 285 sb_size = CX231XX_ISO_NUM_AUDIO_PACKETS * dev->adev.max_pkt_size;
277 286
278 for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { 287 for (i = 0; i < CX231XX_AUDIO_BUFS; i++) {
@@ -331,6 +340,9 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
331 340
332 cx231xx_info("%s: Starting BULK AUDIO transfers\n", __func__); 341 cx231xx_info("%s: Starting BULK AUDIO transfers\n", __func__);
333 342
343 if (dev->state & DEV_DISCONNECTED)
344 return -ENODEV;
345
334 sb_size = CX231XX_NUM_AUDIO_PACKETS * dev->adev.max_pkt_size; 346 sb_size = CX231XX_NUM_AUDIO_PACKETS * dev->adev.max_pkt_size;
335 347
336 for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { 348 for (i = 0; i < CX231XX_AUDIO_BUFS; i++) {
@@ -432,6 +444,11 @@ static int snd_cx231xx_capture_open(struct snd_pcm_substream *substream)
432 return -ENODEV; 444 return -ENODEV;
433 } 445 }
434 446
447 if (dev->state & DEV_DISCONNECTED) {
448 cx231xx_errdev("Can't open. the device was removed.\n");
449 return -ENODEV;
450 }
451
435 /* Sets volume, mute, etc */ 452 /* Sets volume, mute, etc */
436 dev->mute = 0; 453 dev->mute = 0;
437 454
@@ -571,6 +588,9 @@ static int snd_cx231xx_capture_trigger(struct snd_pcm_substream *substream,
571 struct cx231xx *dev = snd_pcm_substream_chip(substream); 588 struct cx231xx *dev = snd_pcm_substream_chip(substream);
572 int retval; 589 int retval;
573 590
591 if (dev->state & DEV_DISCONNECTED)
592 return -ENODEV;
593
574 spin_lock(&dev->adev.slock); 594 spin_lock(&dev->adev.slock);
575 switch (cmd) { 595 switch (cmd) {
576 case SNDRV_PCM_TRIGGER_START: 596 case SNDRV_PCM_TRIGGER_START:
diff --git a/drivers/media/video/cx231xx/cx231xx-cards.c b/drivers/media/video/cx231xx/cx231xx-cards.c
index 1f2fbbfebc76..7577e6e50136 100644
--- a/drivers/media/video/cx231xx/cx231xx-cards.c
+++ b/drivers/media/video/cx231xx/cx231xx-cards.c
@@ -1337,6 +1337,8 @@ static void cx231xx_usb_disconnect(struct usb_interface *interface)
1337 if (!dev->udev) 1337 if (!dev->udev)
1338 return; 1338 return;
1339 1339
1340 dev->state |= DEV_DISCONNECTED;
1341
1340 flush_request_modules(dev); 1342 flush_request_modules(dev);
1341 1343
1342 /* wait until all current v4l2 io is finished then deallocate 1344 /* wait until all current v4l2 io is finished then deallocate
@@ -1354,16 +1356,13 @@ static void cx231xx_usb_disconnect(struct usb_interface *interface)
1354 /* Even having users, it is safe to remove the RC i2c driver */ 1356 /* Even having users, it is safe to remove the RC i2c driver */
1355 cx231xx_ir_exit(dev); 1357 cx231xx_ir_exit(dev);
1356 1358
1357 dev->state |= DEV_MISCONFIGURED;
1358 if (dev->USE_ISO) 1359 if (dev->USE_ISO)
1359 cx231xx_uninit_isoc(dev); 1360 cx231xx_uninit_isoc(dev);
1360 else 1361 else
1361 cx231xx_uninit_bulk(dev); 1362 cx231xx_uninit_bulk(dev);
1362 dev->state |= DEV_DISCONNECTED;
1363 wake_up_interruptible(&dev->wait_frame); 1363 wake_up_interruptible(&dev->wait_frame);
1364 wake_up_interruptible(&dev->wait_stream); 1364 wake_up_interruptible(&dev->wait_stream);
1365 } else { 1365 } else {
1366 dev->state |= DEV_DISCONNECTED;
1367 } 1366 }
1368 1367
1369 cx231xx_close_extension(dev); 1368 cx231xx_close_extension(dev);
diff --git a/drivers/media/video/cx231xx/cx231xx-dvb.c b/drivers/media/video/cx231xx/cx231xx-dvb.c
index da9a4a0aab79..7c4e360ba9bc 100644
--- a/drivers/media/video/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/video/cx231xx/cx231xx-dvb.c
@@ -196,7 +196,7 @@ static inline int dvb_isoc_copy(struct cx231xx *dev, struct urb *urb)
196 if (!dev) 196 if (!dev)
197 return 0; 197 return 0;
198 198
199 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) 199 if (dev->state & DEV_DISCONNECTED)
200 return 0; 200 return 0;
201 201
202 if (urb->status < 0) { 202 if (urb->status < 0) {
@@ -228,7 +228,7 @@ static inline int dvb_bulk_copy(struct cx231xx *dev, struct urb *urb)
228 if (!dev) 228 if (!dev)
229 return 0; 229 return 0;
230 230
231 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) 231 if (dev->state & DEV_DISCONNECTED)
232 return 0; 232 return 0;
233 233
234 if (urb->status < 0) { 234 if (urb->status < 0) {
diff --git a/drivers/media/video/cx231xx/cx231xx-vbi.c b/drivers/media/video/cx231xx/cx231xx-vbi.c
index 1c7a4daafecf..9c5967e1d0c6 100644
--- a/drivers/media/video/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/video/cx231xx/cx231xx-vbi.c
@@ -93,7 +93,7 @@ static inline int cx231xx_isoc_vbi_copy(struct cx231xx *dev, struct urb *urb)
93 if (!dev) 93 if (!dev)
94 return 0; 94 return 0;
95 95
96 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) 96 if (dev->state & DEV_DISCONNECTED)
97 return 0; 97 return 0;
98 98
99 if (urb->status < 0) { 99 if (urb->status < 0) {
diff --git a/drivers/media/video/cx231xx/cx231xx-video.c b/drivers/media/video/cx231xx/cx231xx-video.c
index 6e81f970dc7d..829a41b0c9ef 100644
--- a/drivers/media/video/cx231xx/cx231xx-video.c
+++ b/drivers/media/video/cx231xx/cx231xx-video.c
@@ -337,7 +337,7 @@ static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
337 if (!dev) 337 if (!dev)
338 return 0; 338 return 0;
339 339
340 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) 340 if (dev->state & DEV_DISCONNECTED)
341 return 0; 341 return 0;
342 342
343 if (urb->status < 0) { 343 if (urb->status < 0) {
@@ -440,7 +440,7 @@ static inline int cx231xx_bulk_copy(struct cx231xx *dev, struct urb *urb)
440 if (!dev) 440 if (!dev)
441 return 0; 441 return 0;
442 442
443 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) 443 if (dev->state & DEV_DISCONNECTED)
444 return 0; 444 return 0;
445 445
446 if (urb->status < 0) { 446 if (urb->status < 0) {
@@ -1000,12 +1000,6 @@ static int check_dev(struct cx231xx *dev)
1000 cx231xx_errdev("v4l2 ioctl: device not present\n"); 1000 cx231xx_errdev("v4l2 ioctl: device not present\n");
1001 return -ENODEV; 1001 return -ENODEV;
1002 } 1002 }
1003
1004 if (dev->state & DEV_MISCONFIGURED) {
1005 cx231xx_errdev("v4l2 ioctl: device is misconfigured; "
1006 "close and open it again\n");
1007 return -EIO;
1008 }
1009 return 0; 1003 return 0;
1010} 1004}
1011 1005
@@ -2347,7 +2341,8 @@ static int cx231xx_v4l2_close(struct file *filp)
2347 return 0; 2341 return 0;
2348 } 2342 }
2349 2343
2350 if (dev->users == 1) { 2344 dev->users--;
2345 if (!dev->users) {
2351 videobuf_stop(&fh->vb_vidq); 2346 videobuf_stop(&fh->vb_vidq);
2352 videobuf_mmap_free(&fh->vb_vidq); 2347 videobuf_mmap_free(&fh->vb_vidq);
2353 2348
@@ -2374,7 +2369,6 @@ static int cx231xx_v4l2_close(struct file *filp)
2374 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); 2369 cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0);
2375 } 2370 }
2376 kfree(fh); 2371 kfree(fh);
2377 dev->users--;
2378 wake_up_interruptible_nr(&dev->open, 1); 2372 wake_up_interruptible_nr(&dev->open, 1);
2379 return 0; 2373 return 0;
2380} 2374}
diff --git a/drivers/media/video/cx231xx/cx231xx.h b/drivers/media/video/cx231xx/cx231xx.h
index 5d498a4112d7..e17447554a0d 100644
--- a/drivers/media/video/cx231xx/cx231xx.h
+++ b/drivers/media/video/cx231xx/cx231xx.h
@@ -377,7 +377,6 @@ struct cx231xx_board {
377enum cx231xx_dev_state { 377enum cx231xx_dev_state {
378 DEV_INITIALIZED = 0x01, 378 DEV_INITIALIZED = 0x01,
379 DEV_DISCONNECTED = 0x02, 379 DEV_DISCONNECTED = 0x02,
380 DEV_MISCONFIGURED = 0x04,
381}; 380};
382 381
383enum AFE_MODE { 382enum AFE_MODE {