Skip to content

Commit

Permalink
V4L/DVB (13061): radio-mr800: simplify video_device allocation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Ellingsworth authored and Mauro Carvalho Chehab committed Dec 5, 2009
1 parent 4aebc28 commit 7a7d92e
Showing 1 changed file with 21 additions and 32 deletions.
53 changes: 21 additions & 32 deletions drivers/media/radio/radio-mr800.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int usb_amradio_resume(struct usb_interface *intf);
struct amradio_device {
/* reference to USB and video device */
struct usb_device *usbdev;
struct video_device *videodev;
struct video_device videodev;
struct v4l2_device v4l2_dev;

unsigned char *buffer;
Expand Down Expand Up @@ -272,7 +272,7 @@ static void usb_amradio_disconnect(struct usb_interface *intf)
mutex_unlock(&radio->lock);

usb_set_intfdata(intf, NULL);
video_unregister_device(radio->videodev);
video_unregister_device(&radio->videodev);
v4l2_device_disconnect(&radio->v4l2_dev);
}

Expand Down Expand Up @@ -320,7 +320,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
*/
retval = amradio_set_stereo(radio, WANT_STEREO);
if (retval < 0)
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"set stereo failed\n");

strcpy(v->name, "FM");
Expand Down Expand Up @@ -366,13 +366,13 @@ static int vidioc_s_tuner(struct file *file, void *priv,
case V4L2_TUNER_MODE_MONO:
retval = amradio_set_stereo(radio, WANT_MONO);
if (retval < 0)
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"set mono failed\n");
break;
case V4L2_TUNER_MODE_STEREO:
retval = amradio_set_stereo(radio, WANT_STEREO);
if (retval < 0)
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"set stereo failed\n");
break;
default:
Expand Down Expand Up @@ -403,7 +403,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,

retval = amradio_setfreq(radio, radio->curfreq);
if (retval < 0)
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"set frequency failed\n");

unlock:
Expand Down Expand Up @@ -493,13 +493,13 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
if (ctrl->value) {
retval = amradio_set_mute(radio, AMRADIO_STOP);
if (retval < 0) {
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"amradio_stop failed\n");
}
} else {
retval = amradio_set_mute(radio, AMRADIO_START);
if (retval < 0) {
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"amradio_start failed\n");
}
}
Expand Down Expand Up @@ -565,20 +565,20 @@ static int usb_amradio_open(struct file *file)

retval = amradio_set_mute(radio, AMRADIO_START);
if (retval < 0) {
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"radio did not start up properly\n");
radio->users = 0;
goto unlock;
}

retval = amradio_set_stereo(radio, WANT_STEREO);
if (retval < 0)
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"set stereo failed\n");

retval = amradio_setfreq(radio, radio->curfreq);
if (retval < 0)
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"set frequency failed\n");

unlock:
Expand All @@ -604,7 +604,7 @@ static int usb_amradio_close(struct file *file)
if (!radio->removed) {
retval = amradio_set_mute(radio, AMRADIO_STOP);
if (retval < 0)
amradio_dev_warn(&radio->videodev->dev,
amradio_dev_warn(&radio->videodev.dev,
"amradio_stop failed\n");
}

Expand Down Expand Up @@ -676,9 +676,6 @@ static void usb_amradio_video_device_release(struct video_device *videodev)
{
struct amradio_device *radio = video_get_drvdata(videodev);

/* we call v4l to free radio->videodev */
video_device_release(videodev);

v4l2_device_unregister(&radio->v4l2_dev);

/* free rest memory */
Expand Down Expand Up @@ -718,20 +715,12 @@ static int usb_amradio_probe(struct usb_interface *intf,
return retval;
}

radio->videodev = video_device_alloc();

if (!radio->videodev) {
dev_err(&intf->dev, "video_device_alloc failed\n");
kfree(radio->buffer);
kfree(radio);
return -ENOMEM;
}

strlcpy(radio->videodev->name, v4l2_dev->name, sizeof(radio->videodev->name));
radio->videodev->v4l2_dev = v4l2_dev;
radio->videodev->fops = &usb_amradio_fops;
radio->videodev->ioctl_ops = &usb_amradio_ioctl_ops;
radio->videodev->release = usb_amradio_video_device_release;
strlcpy(radio->videodev.name, v4l2_dev->name,
sizeof(radio->videodev.name));
radio->videodev.v4l2_dev = v4l2_dev;
radio->videodev.fops = &usb_amradio_fops;
radio->videodev.ioctl_ops = &usb_amradio_ioctl_ops;
radio->videodev.release = usb_amradio_video_device_release;

radio->removed = 0;
radio->users = 0;
Expand All @@ -741,12 +730,12 @@ static int usb_amradio_probe(struct usb_interface *intf,

mutex_init(&radio->lock);

video_set_drvdata(radio->videodev, radio);
video_set_drvdata(&radio->videodev, radio);

retval = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr);
retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO,
radio_nr);
if (retval < 0) {
dev_err(&intf->dev, "could not register video device\n");
video_device_release(radio->videodev);
v4l2_device_unregister(v4l2_dev);
kfree(radio->buffer);
kfree(radio);
Expand Down

0 comments on commit 7a7d92e

Please sign in to comment.