diff options
author | David Ellingsworth <david@identd.dyndns.org> | 2009-09-23 16:49:36 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-12-05 15:40:09 -0500 |
commit | eac000a90e70b990c7d847ac40ff1c33a5f00636 (patch) | |
tree | a46b69c6b8dcd9df59b682c984c535b68c30b060 /drivers | |
parent | ceb99e1b5a093ae8f439fc55aac28d007145c8ec (diff) |
V4L/DVB (13065): radio-mr800: simplify locking in ioctl callbacks
Simplify locking in ioctl callbacks.
Signed-off-by: David Ellingsworth <david@identd.dyndns.org>
Acked-by: Alexey Klimov <klimov.linux@gmail.com>
Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/radio/radio-mr800.c | 109 |
1 files changed, 30 insertions, 79 deletions
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c index 5401952004bc..0498c4c60d8c 100644 --- a/drivers/media/radio/radio-mr800.c +++ b/drivers/media/radio/radio-mr800.c | |||
@@ -299,18 +299,8 @@ static int vidioc_g_tuner(struct file *file, void *priv, | |||
299 | struct amradio_device *radio = file->private_data; | 299 | struct amradio_device *radio = file->private_data; |
300 | int retval; | 300 | int retval; |
301 | 301 | ||
302 | mutex_lock(&radio->lock); | 302 | if (v->index > 0) |
303 | 303 | return -EINVAL; | |
304 | /* safety check */ | ||
305 | if (radio->removed) { | ||
306 | retval = -EIO; | ||
307 | goto unlock; | ||
308 | } | ||
309 | |||
310 | if (v->index > 0) { | ||
311 | retval = -EINVAL; | ||
312 | goto unlock; | ||
313 | } | ||
314 | 304 | ||
315 | /* TODO: Add function which look is signal stereo or not | 305 | /* TODO: Add function which look is signal stereo or not |
316 | * amradio_getstat(radio); | 306 | * amradio_getstat(radio); |
@@ -338,8 +328,6 @@ static int vidioc_g_tuner(struct file *file, void *priv, | |||
338 | v->signal = 0xffff; /* Can't get the signal strength, sad.. */ | 328 | v->signal = 0xffff; /* Can't get the signal strength, sad.. */ |
339 | v->afc = 0; /* Don't know what is this */ | 329 | v->afc = 0; /* Don't know what is this */ |
340 | 330 | ||
341 | unlock: | ||
342 | mutex_unlock(&radio->lock); | ||
343 | return retval; | 331 | return retval; |
344 | } | 332 | } |
345 | 333 | ||
@@ -348,20 +336,10 @@ static int vidioc_s_tuner(struct file *file, void *priv, | |||
348 | struct v4l2_tuner *v) | 336 | struct v4l2_tuner *v) |
349 | { | 337 | { |
350 | struct amradio_device *radio = file->private_data; | 338 | struct amradio_device *radio = file->private_data; |
351 | int retval; | 339 | int retval = -EINVAL; |
352 | |||
353 | mutex_lock(&radio->lock); | ||
354 | |||
355 | /* safety check */ | ||
356 | if (radio->removed) { | ||
357 | retval = -EIO; | ||
358 | goto unlock; | ||
359 | } | ||
360 | 340 | ||
361 | if (v->index > 0) { | 341 | if (v->index > 0) |
362 | retval = -EINVAL; | 342 | return -EINVAL; |
363 | goto unlock; | ||
364 | } | ||
365 | 343 | ||
366 | /* mono/stereo selector */ | 344 | /* mono/stereo selector */ |
367 | switch (v->audmode) { | 345 | switch (v->audmode) { |
@@ -377,12 +355,8 @@ static int vidioc_s_tuner(struct file *file, void *priv, | |||
377 | amradio_dev_warn(&radio->videodev.dev, | 355 | amradio_dev_warn(&radio->videodev.dev, |
378 | "set stereo failed\n"); | 356 | "set stereo failed\n"); |
379 | break; | 357 | break; |
380 | default: | ||
381 | retval = -EINVAL; | ||
382 | } | 358 | } |
383 | 359 | ||
384 | unlock: | ||
385 | mutex_unlock(&radio->lock); | ||
386 | return retval; | 360 | return retval; |
387 | } | 361 | } |
388 | 362 | ||
@@ -391,15 +365,7 @@ static int vidioc_s_frequency(struct file *file, void *priv, | |||
391 | struct v4l2_frequency *f) | 365 | struct v4l2_frequency *f) |
392 | { | 366 | { |
393 | struct amradio_device *radio = file->private_data; | 367 | struct amradio_device *radio = file->private_data; |
394 | int retval; | 368 | int retval = 0; |
395 | |||
396 | mutex_lock(&radio->lock); | ||
397 | |||
398 | /* safety check */ | ||
399 | if (radio->removed) { | ||
400 | retval = -EIO; | ||
401 | goto unlock; | ||
402 | } | ||
403 | 369 | ||
404 | radio->curfreq = f->frequency; | 370 | radio->curfreq = f->frequency; |
405 | 371 | ||
@@ -408,8 +374,6 @@ static int vidioc_s_frequency(struct file *file, void *priv, | |||
408 | amradio_dev_warn(&radio->videodev.dev, | 374 | amradio_dev_warn(&radio->videodev.dev, |
409 | "set frequency failed\n"); | 375 | "set frequency failed\n"); |
410 | 376 | ||
411 | unlock: | ||
412 | mutex_unlock(&radio->lock); | ||
413 | return retval; | 377 | return retval; |
414 | } | 378 | } |
415 | 379 | ||
@@ -418,22 +382,11 @@ static int vidioc_g_frequency(struct file *file, void *priv, | |||
418 | struct v4l2_frequency *f) | 382 | struct v4l2_frequency *f) |
419 | { | 383 | { |
420 | struct amradio_device *radio = file->private_data; | 384 | struct amradio_device *radio = file->private_data; |
421 | int retval = 0; | ||
422 | |||
423 | mutex_lock(&radio->lock); | ||
424 | |||
425 | /* safety check */ | ||
426 | if (radio->removed) { | ||
427 | retval = -EIO; | ||
428 | goto unlock; | ||
429 | } | ||
430 | 385 | ||
431 | f->type = V4L2_TUNER_RADIO; | 386 | f->type = V4L2_TUNER_RADIO; |
432 | f->frequency = radio->curfreq; | 387 | f->frequency = radio->curfreq; |
433 | 388 | ||
434 | unlock: | 389 | return 0; |
435 | mutex_unlock(&radio->lock); | ||
436 | return retval; | ||
437 | } | 390 | } |
438 | 391 | ||
439 | /* vidioc_queryctrl - enumerate control items */ | 392 | /* vidioc_queryctrl - enumerate control items */ |
@@ -453,26 +406,14 @@ static int vidioc_g_ctrl(struct file *file, void *priv, | |||
453 | struct v4l2_control *ctrl) | 406 | struct v4l2_control *ctrl) |
454 | { | 407 | { |
455 | struct amradio_device *radio = file->private_data; | 408 | struct amradio_device *radio = file->private_data; |
456 | int retval = -EINVAL; | ||
457 | |||
458 | mutex_lock(&radio->lock); | ||
459 | |||
460 | /* safety check */ | ||
461 | if (radio->removed) { | ||
462 | retval = -EIO; | ||
463 | goto unlock; | ||
464 | } | ||
465 | 409 | ||
466 | switch (ctrl->id) { | 410 | switch (ctrl->id) { |
467 | case V4L2_CID_AUDIO_MUTE: | 411 | case V4L2_CID_AUDIO_MUTE: |
468 | ctrl->value = radio->muted; | 412 | ctrl->value = radio->muted; |
469 | retval = 0; | 413 | return 0; |
470 | break; | ||
471 | } | 414 | } |
472 | 415 | ||
473 | unlock: | 416 | return -EINVAL; |
474 | mutex_unlock(&radio->lock); | ||
475 | return retval; | ||
476 | } | 417 | } |
477 | 418 | ||
478 | /* vidioc_s_ctrl - set the value of a control */ | 419 | /* vidioc_s_ctrl - set the value of a control */ |
@@ -482,14 +423,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv, | |||
482 | struct amradio_device *radio = file->private_data; | 423 | struct amradio_device *radio = file->private_data; |
483 | int retval = -EINVAL; | 424 | int retval = -EINVAL; |
484 | 425 | ||
485 | mutex_lock(&radio->lock); | ||
486 | |||
487 | /* safety check */ | ||
488 | if (radio->removed) { | ||
489 | retval = -EIO; | ||
490 | goto unlock; | ||
491 | } | ||
492 | |||
493 | switch (ctrl->id) { | 426 | switch (ctrl->id) { |
494 | case V4L2_CID_AUDIO_MUTE: | 427 | case V4L2_CID_AUDIO_MUTE: |
495 | if (ctrl->value) { | 428 | if (ctrl->value) { |
@@ -508,8 +441,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv, | |||
508 | break; | 441 | break; |
509 | } | 442 | } |
510 | 443 | ||
511 | unlock: | ||
512 | mutex_unlock(&radio->lock); | ||
513 | return retval; | 444 | return retval; |
514 | } | 445 | } |
515 | 446 | ||
@@ -616,6 +547,26 @@ unlock: | |||
616 | return retval; | 547 | return retval; |
617 | } | 548 | } |
618 | 549 | ||
550 | static long usb_amradio_ioctl(struct file *file, unsigned int cmd, | ||
551 | unsigned long arg) | ||
552 | { | ||
553 | struct amradio_device *radio = file->private_data; | ||
554 | long retval = 0; | ||
555 | |||
556 | mutex_lock(&radio->lock); | ||
557 | |||
558 | if (radio->removed) { | ||
559 | retval = -EIO; | ||
560 | goto unlock; | ||
561 | } | ||
562 | |||
563 | retval = video_ioctl2(file, cmd, arg); | ||
564 | |||
565 | unlock: | ||
566 | mutex_unlock(&radio->lock); | ||
567 | return retval; | ||
568 | } | ||
569 | |||
619 | /* Suspend device - stop device. Need to be checked and fixed */ | 570 | /* Suspend device - stop device. Need to be checked and fixed */ |
620 | static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message) | 571 | static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message) |
621 | { | 572 | { |
@@ -657,7 +608,7 @@ static const struct v4l2_file_operations usb_amradio_fops = { | |||
657 | .owner = THIS_MODULE, | 608 | .owner = THIS_MODULE, |
658 | .open = usb_amradio_open, | 609 | .open = usb_amradio_open, |
659 | .release = usb_amradio_close, | 610 | .release = usb_amradio_close, |
660 | .ioctl = video_ioctl2, | 611 | .ioctl = usb_amradio_ioctl, |
661 | }; | 612 | }; |
662 | 613 | ||
663 | static const struct v4l2_ioctl_ops usb_amradio_ioctl_ops = { | 614 | static const struct v4l2_ioctl_ops usb_amradio_ioctl_ops = { |