[media] radio-bcm2048: embed video_device

Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
This commit is contained in:
Hans Verkuil 2015-03-09 13:33:58 -03:00 committed by Mauro Carvalho Chehab
parent 3ae863e0db
commit 54ad7b9d42
1 changed files with 9 additions and 24 deletions

View File

@ -279,7 +279,7 @@ struct region_info {
struct bcm2048_device { struct bcm2048_device {
struct i2c_client *client; struct i2c_client *client;
struct video_device *videodev; struct video_device videodev;
struct work_struct work; struct work_struct work;
struct completion compl; struct completion compl;
struct mutex mutex; struct mutex mutex;
@ -2583,7 +2583,7 @@ static struct v4l2_ioctl_ops bcm2048_ioctl_ops = {
static struct video_device bcm2048_viddev_template = { static struct video_device bcm2048_viddev_template = {
.fops = &bcm2048_fops, .fops = &bcm2048_fops,
.name = BCM2048_DRIVER_NAME, .name = BCM2048_DRIVER_NAME,
.release = video_device_release, .release = video_device_release_empty,
.ioctl_ops = &bcm2048_ioctl_ops, .ioctl_ops = &bcm2048_ioctl_ops,
}; };
@ -2602,13 +2602,6 @@ static int bcm2048_i2c_driver_probe(struct i2c_client *client,
goto exit; goto exit;
} }
bdev->videodev = video_device_alloc();
if (!bdev->videodev) {
dev_dbg(&client->dev, "Failed to alloc video device.\n");
err = -ENOMEM;
goto free_bdev;
}
bdev->client = client; bdev->client = client;
i2c_set_clientdata(client, bdev); i2c_set_clientdata(client, bdev);
mutex_init(&bdev->mutex); mutex_init(&bdev->mutex);
@ -2621,16 +2614,16 @@ static int bcm2048_i2c_driver_probe(struct i2c_client *client,
client->name, bdev); client->name, bdev);
if (err < 0) { if (err < 0) {
dev_err(&client->dev, "Could not request IRQ\n"); dev_err(&client->dev, "Could not request IRQ\n");
goto free_vdev; goto free_bdev;
} }
dev_dbg(&client->dev, "IRQ requested.\n"); dev_dbg(&client->dev, "IRQ requested.\n");
} else { } else {
dev_dbg(&client->dev, "IRQ not configured. Using timeouts.\n"); dev_dbg(&client->dev, "IRQ not configured. Using timeouts.\n");
} }
*bdev->videodev = bcm2048_viddev_template; bdev->videodev = bcm2048_viddev_template;
video_set_drvdata(bdev->videodev, bdev); video_set_drvdata(&bdev->videodev, bdev);
if (video_register_device(bdev->videodev, VFL_TYPE_RADIO, radio_nr)) { if (video_register_device(&bdev->videodev, VFL_TYPE_RADIO, radio_nr)) {
dev_dbg(&client->dev, "Could not register video device.\n"); dev_dbg(&client->dev, "Could not register video device.\n");
err = -EIO; err = -EIO;
goto free_irq; goto free_irq;
@ -2653,18 +2646,13 @@ static int bcm2048_i2c_driver_probe(struct i2c_client *client,
free_sysfs: free_sysfs:
bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs)); bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs));
free_registration: free_registration:
video_unregister_device(bdev->videodev); video_unregister_device(&bdev->videodev);
/* video_unregister_device frees bdev->videodev */
bdev->videodev = NULL;
skip_release = 1; skip_release = 1;
free_irq: free_irq:
if (client->irq) if (client->irq)
free_irq(client->irq, bdev); free_irq(client->irq, bdev);
free_vdev:
if (!skip_release)
video_device_release(bdev->videodev);
i2c_set_clientdata(client, NULL);
free_bdev: free_bdev:
i2c_set_clientdata(client, NULL);
kfree(bdev); kfree(bdev);
exit: exit:
return err; return err;
@ -2673,16 +2661,13 @@ exit:
static int __exit bcm2048_i2c_driver_remove(struct i2c_client *client) static int __exit bcm2048_i2c_driver_remove(struct i2c_client *client)
{ {
struct bcm2048_device *bdev = i2c_get_clientdata(client); struct bcm2048_device *bdev = i2c_get_clientdata(client);
struct video_device *vd;
if (!client->adapter) if (!client->adapter)
return -ENODEV; return -ENODEV;
if (bdev) { if (bdev) {
vd = bdev->videodev;
bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs)); bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs));
video_unregister_device(vd); video_unregister_device(&bdev->videodev);
if (bdev->power_state) if (bdev->power_state)
bcm2048_set_power_state(bdev, BCM2048_POWER_OFF); bcm2048_set_power_state(bdev, BCM2048_POWER_OFF);