aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ellingsworth <david@identd.dyndns.org>2009-09-22 20:37:30 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-12-05 15:40:07 -0500
commit7a7d92e061ed13052d306cadad6972d52acea931 (patch)
tree6e933de93e8fa9f4ea48c2ed60a1af6d70f7dc6e
parent4aebc2893eada9e054a37df8bb342a53f8ca0d2a (diff)
V4L/DVB (13061): radio-mr800: simplify video_device allocation
simplify video_device allocation 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>
-rw-r--r--drivers/media/radio/radio-mr800.c53
1 files changed, 21 insertions, 32 deletions
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
index 75c69755a04c..dd36ba0baab3 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -129,7 +129,7 @@ static int usb_amradio_resume(struct usb_interface *intf);
129struct amradio_device { 129struct amradio_device {
130 /* reference to USB and video device */ 130 /* reference to USB and video device */
131 struct usb_device *usbdev; 131 struct usb_device *usbdev;
132 struct video_device *videodev; 132 struct video_device videodev;
133 struct v4l2_device v4l2_dev; 133 struct v4l2_device v4l2_dev;
134 134
135 unsigned char *buffer; 135 unsigned char *buffer;
@@ -272,7 +272,7 @@ static void usb_amradio_disconnect(struct usb_interface *intf)
272 mutex_unlock(&radio->lock); 272 mutex_unlock(&radio->lock);
273 273
274 usb_set_intfdata(intf, NULL); 274 usb_set_intfdata(intf, NULL);
275 video_unregister_device(radio->videodev); 275 video_unregister_device(&radio->videodev);
276 v4l2_device_disconnect(&radio->v4l2_dev); 276 v4l2_device_disconnect(&radio->v4l2_dev);
277} 277}
278 278
@@ -320,7 +320,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
320 */ 320 */
321 retval = amradio_set_stereo(radio, WANT_STEREO); 321 retval = amradio_set_stereo(radio, WANT_STEREO);
322 if (retval < 0) 322 if (retval < 0)
323 amradio_dev_warn(&radio->videodev->dev, 323 amradio_dev_warn(&radio->videodev.dev,
324 "set stereo failed\n"); 324 "set stereo failed\n");
325 325
326 strcpy(v->name, "FM"); 326 strcpy(v->name, "FM");
@@ -366,13 +366,13 @@ static int vidioc_s_tuner(struct file *file, void *priv,
366 case V4L2_TUNER_MODE_MONO: 366 case V4L2_TUNER_MODE_MONO:
367 retval = amradio_set_stereo(radio, WANT_MONO); 367 retval = amradio_set_stereo(radio, WANT_MONO);
368 if (retval < 0) 368 if (retval < 0)
369 amradio_dev_warn(&radio->videodev->dev, 369 amradio_dev_warn(&radio->videodev.dev,
370 "set mono failed\n"); 370 "set mono failed\n");
371 break; 371 break;
372 case V4L2_TUNER_MODE_STEREO: 372 case V4L2_TUNER_MODE_STEREO:
373 retval = amradio_set_stereo(radio, WANT_STEREO); 373 retval = amradio_set_stereo(radio, WANT_STEREO);
374 if (retval < 0) 374 if (retval < 0)
375 amradio_dev_warn(&radio->videodev->dev, 375 amradio_dev_warn(&radio->videodev.dev,
376 "set stereo failed\n"); 376 "set stereo failed\n");
377 break; 377 break;
378 default: 378 default:
@@ -403,7 +403,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
403 403
404 retval = amradio_setfreq(radio, radio->curfreq); 404 retval = amradio_setfreq(radio, radio->curfreq);
405 if (retval < 0) 405 if (retval < 0)
406 amradio_dev_warn(&radio->videodev->dev, 406 amradio_dev_warn(&radio->videodev.dev,
407 "set frequency failed\n"); 407 "set frequency failed\n");
408 408
409unlock: 409unlock:
@@ -493,13 +493,13 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
493 if (ctrl->value) { 493 if (ctrl->value) {
494 retval = amradio_set_mute(radio, AMRADIO_STOP); 494 retval = amradio_set_mute(radio, AMRADIO_STOP);
495 if (retval < 0) { 495 if (retval < 0) {
496 amradio_dev_warn(&radio->videodev->dev, 496 amradio_dev_warn(&radio->videodev.dev,
497 "amradio_stop failed\n"); 497 "amradio_stop failed\n");
498 } 498 }
499 } else { 499 } else {
500 retval = amradio_set_mute(radio, AMRADIO_START); 500 retval = amradio_set_mute(radio, AMRADIO_START);
501 if (retval < 0) { 501 if (retval < 0) {
502 amradio_dev_warn(&radio->videodev->dev, 502 amradio_dev_warn(&radio->videodev.dev,
503 "amradio_start failed\n"); 503 "amradio_start failed\n");
504 } 504 }
505 } 505 }
@@ -565,7 +565,7 @@ static int usb_amradio_open(struct file *file)
565 565
566 retval = amradio_set_mute(radio, AMRADIO_START); 566 retval = amradio_set_mute(radio, AMRADIO_START);
567 if (retval < 0) { 567 if (retval < 0) {
568 amradio_dev_warn(&radio->videodev->dev, 568 amradio_dev_warn(&radio->videodev.dev,
569 "radio did not start up properly\n"); 569 "radio did not start up properly\n");
570 radio->users = 0; 570 radio->users = 0;
571 goto unlock; 571 goto unlock;
@@ -573,12 +573,12 @@ static int usb_amradio_open(struct file *file)
573 573
574 retval = amradio_set_stereo(radio, WANT_STEREO); 574 retval = amradio_set_stereo(radio, WANT_STEREO);
575 if (retval < 0) 575 if (retval < 0)
576 amradio_dev_warn(&radio->videodev->dev, 576 amradio_dev_warn(&radio->videodev.dev,
577 "set stereo failed\n"); 577 "set stereo failed\n");
578 578
579 retval = amradio_setfreq(radio, radio->curfreq); 579 retval = amradio_setfreq(radio, radio->curfreq);
580 if (retval < 0) 580 if (retval < 0)
581 amradio_dev_warn(&radio->videodev->dev, 581 amradio_dev_warn(&radio->videodev.dev,
582 "set frequency failed\n"); 582 "set frequency failed\n");
583 583
584unlock: 584unlock:
@@ -604,7 +604,7 @@ static int usb_amradio_close(struct file *file)
604 if (!radio->removed) { 604 if (!radio->removed) {
605 retval = amradio_set_mute(radio, AMRADIO_STOP); 605 retval = amradio_set_mute(radio, AMRADIO_STOP);
606 if (retval < 0) 606 if (retval < 0)
607 amradio_dev_warn(&radio->videodev->dev, 607 amradio_dev_warn(&radio->videodev.dev,
608 "amradio_stop failed\n"); 608 "amradio_stop failed\n");
609 } 609 }
610 610
@@ -676,9 +676,6 @@ static void usb_amradio_video_device_release(struct video_device *videodev)
676{ 676{
677 struct amradio_device *radio = video_get_drvdata(videodev); 677 struct amradio_device *radio = video_get_drvdata(videodev);
678 678
679 /* we call v4l to free radio->videodev */
680 video_device_release(videodev);
681
682 v4l2_device_unregister(&radio->v4l2_dev); 679 v4l2_device_unregister(&radio->v4l2_dev);
683 680
684 /* free rest memory */ 681 /* free rest memory */
@@ -718,20 +715,12 @@ static int usb_amradio_probe(struct usb_interface *intf,
718 return retval; 715 return retval;
719 } 716 }
720 717
721 radio->videodev = video_device_alloc(); 718 strlcpy(radio->videodev.name, v4l2_dev->name,
722 719 sizeof(radio->videodev.name));
723 if (!radio->videodev) { 720 radio->videodev.v4l2_dev = v4l2_dev;
724 dev_err(&intf->dev, "video_device_alloc failed\n"); 721 radio->videodev.fops = &usb_amradio_fops;
725 kfree(radio->buffer); 722 radio->videodev.ioctl_ops = &usb_amradio_ioctl_ops;
726 kfree(radio); 723 radio->videodev.release = usb_amradio_video_device_release;
727 return -ENOMEM;
728 }
729
730 strlcpy(radio->videodev->name, v4l2_dev->name, sizeof(radio->videodev->name));
731 radio->videodev->v4l2_dev = v4l2_dev;
732 radio->videodev->fops = &usb_amradio_fops;
733 radio->videodev->ioctl_ops = &usb_amradio_ioctl_ops;
734 radio->videodev->release = usb_amradio_video_device_release;
735 724
736 radio->removed = 0; 725 radio->removed = 0;
737 radio->users = 0; 726 radio->users = 0;
@@ -741,12 +730,12 @@ static int usb_amradio_probe(struct usb_interface *intf,
741 730
742 mutex_init(&radio->lock); 731 mutex_init(&radio->lock);
743 732
744 video_set_drvdata(radio->videodev, radio); 733 video_set_drvdata(&radio->videodev, radio);
745 734
746 retval = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr); 735 retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO,
736 radio_nr);
747 if (retval < 0) { 737 if (retval < 0) {
748 dev_err(&intf->dev, "could not register video device\n"); 738 dev_err(&intf->dev, "could not register video device\n");
749 video_device_release(radio->videodev);
750 v4l2_device_unregister(v4l2_dev); 739 v4l2_device_unregister(v4l2_dev);
751 kfree(radio->buffer); 740 kfree(radio->buffer);
752 kfree(radio); 741 kfree(radio);