media: sh_vou: trivial cleanups
cover media: sh_vou: trivial cleanups
From: "Lad, Prabhakar" <[email protected]>
Hi,
This series is trivial cleanup for sh_vou driver.
Cheers,
--Prabhakar Lad
Lad, Prabhakar (2):
media: sh_vou: embed video_device
media: sh_vou: use devres api
drivers/media/platform/sh_vou.c | 72 ++++++++++------------------------------- 1 file changed, 17 insertions(+), 55 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 media: sh_vou: embed video_device
From: "Lad, Prabhakar" <[email protected]>
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 Lad, Prabhakar <[email protected]>
--- drivers/media/platform/sh_vou.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/media/platform/sh_vou.c +6 -15
@@ -62,7 +62,7 @@ enum sh_vou_status {struct sh_vou_device {struct v4l2_device v4l2_dev; -struct video_device *vdev; +struct video_device vdev;atomic_t use_count;struct sh_vou_pdata *pdata;spinlock_t lock;
@@ -890,7 +890,7 @@ static int sh_vou_s_std(struct file *file, void *priv, v4l2_std_id std_id)dev_dbg (vou_dev->v4l2_dev.dev,"%s(): 0x%llx\n" , __func__, std_id); -if (std_id & ~vou_dev->vdev->tvnorms) +if (std_id & ~vou_dev->vdev.tvnorms)return -EINVAL ; ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video,
@@ -1193,7 +1193,7 @@ static int sh_vou_open(struct file *file)V4L2_BUF_TYPE_VIDEO_OUTPUT ,V4L2_FIELD_NONE ,sizeof (struct videobuf_buffer ), - vou_dev->vdev, &vou_dev->fop_lock); + &vou_dev->vdev, &vou_dev->fop_lock);mutex_unlock (&vou_dev->fop_lock); file->private_data = vou_file;
@@ -1361,21 +1361,14 @@ static int sh_vou_probe(struct platform_device *pdev) goto ev4l2devreg; } -/* Allocate memory for video device */ - vdev =video_device_alloc (); -if (vdev ==NULL ) { - ret = -ENOMEM ; - goto evdevalloc; - } - + vdev = &vou_dev->vdev; *vdev = sh_vou_video_template;if (vou_pdata->bus_fmt ==SH_VOU_BUS_8BIT ) vdev->tvnorms |=V4L2_STD_PAL ; vdev->v4l2_dev = &vou_dev->v4l2_dev; - vdev->release = video_device_release; + vdev->release = video_device_release_empty; vdev->lock = &vou_dev->fop_lock; - vou_dev->vdev = vdev;video_set_drvdata (vdev, vou_dev);pm_runtime_enable (&pdev->dev);
@@ -1409,9 +1402,7 @@ ei2cnd: ereset:i2c_put_adapter (i2c_adap); ei2cgadap: -video_device_release (vdev);pm_runtime_disable (&pdev->dev); -evdevalloc:v4l2_device_unregister (&vou_dev->v4l2_dev); ev4l2devreg:free_irq (irq, vou_dev);
@@ -1438,7 +1429,7 @@ static int sh_vou_remove(struct platform_device *pdev)if (irq >0 )free_irq (irq, vou_dev);pm_runtime_disable (&pdev->dev); -video_unregister_device (vou_dev->vdev); +video_unregister_device (&vou_dev->vdev);i2c_put_adapter (client->adapter);v4l2_device_unregister (&vou_dev->v4l2_dev);iounmap (vou_dev->base);
Signature · 1 line
2.1.0
PATCH 2/2 media: sh_vou: use devres api
In reply to Lad PrabhakarFrom: "Lad, Prabhakar" <[email protected]>
use devres API while allocating resources so that these resources are released automatically on driver detach.
Signed-off-by Lad, Prabhakar <[email protected]>
--- drivers/media/platform/sh_vou.c | 51 +++++++++-------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-)
drivers/media/platform/sh_vou.c +11 -40
@@ -1297,7 +1297,7 @@ static int sh_vou_probe(struct platform_device *pdev)struct i2c_adapter *i2c_adap;struct video_device *vdev;struct sh_vou_device *vou_dev; -struct resource *reg_res, *region; +struct resource *reg_res;struct v4l2_subdev *subdev;int irq, ret;
@@ -1309,7 +1309,7 @@ static int sh_vou_probe(struct platform_device *pdev)return -ENODEV ; } - vou_dev =kzalloc (sizeof (*vou_dev),GFP_KERNEL ); + vou_dev =devm_kzalloc (&pdev->dev,sizeof (*vou_dev),GFP_KERNEL );if (!vou_dev)return -ENOMEM ;
@@ -1337,28 +1337,18 @@ static int sh_vou_probe(struct platform_device *pdev) pix->sizeimage =VOU_MAX_IMAGE_WIDTH *2 *480 ; pix->colorspace =V4L2_COLORSPACE_SMPTE170M ; - region =request_mem_region (reg_res->start,resource_size (reg_res), - pdev->name); -if (!region) { -dev_err (&pdev->dev,"VOU region already claimed\n" ); - ret = -EBUSY ; - goto ereqmemreg; - } - - vou_dev->base =ioremap (reg_res->start,resource_size (reg_res)); -if (!vou_dev->base) { - ret = -ENOMEM ; - goto emap; - } + vou_dev->base =devm_ioremap_resource (&pdev->dev, reg_res); +if (IS_ERR (vou_dev->base)) +return PTR_ERR (vou_dev->base); - ret =request_irq (irq, sh_vou_isr,0 ,"vou" , vou_dev); -if (ret <0 ) - goto ereqirq; + ret =devm_request_irq (&pdev->dev, irq, sh_vou_isr,0 ,"vou" , vou_dev); +if (ret) +return ret; ret =v4l2_device_register (&pdev->dev, &vou_dev->v4l2_dev);if (ret <0 ) {dev_err (&pdev->dev,"Error registering v4l2 device\n" ); - goto ev4l2devreg; +return ret; } vdev = &vou_dev->vdev;
@@ -1382,7 +1372,7 @@ static int sh_vou_probe(struct platform_device *pdev) ret =sh_vou_hw_init (vou_dev);if (ret <0 ) - goto ereset; + goto ei2cnd; subdev =v4l2_i2c_new_subdev_board (&vou_dev->v4l2_dev, i2c_adap, vou_pdata->board_info,NULL );
@@ -1393,50 +1383,31 @@ static int sh_vou_probe(struct platform_device *pdev) ret =video_register_device (vdev,VFL_TYPE_GRABBER ,-1 );if (ret <0 ) - goto evregdev; + goto ei2cnd;return 0 ; -evregdev: ei2cnd: -ereset:i2c_put_adapter (i2c_adap); ei2cgadap:pm_runtime_disable (&pdev->dev);v4l2_device_unregister (&vou_dev->v4l2_dev); -ev4l2devreg: -free_irq (irq, vou_dev); -ereqirq: -iounmap (vou_dev->base); -emap: -release_mem_region (reg_res->start,resource_size (reg_res)); -ereqmemreg: -kfree (vou_dev);return ret; }static int sh_vou_remove (struct platform_device *pdev) { -int irq =platform_get_irq (pdev,0 );struct v4l2_device *v4l2_dev =platform_get_drvdata (pdev);struct sh_vou_device *vou_dev =container_of (v4l2_dev, struct sh_vou_device, v4l2_dev);struct v4l2_subdev *sd =list_entry (v4l2_dev->subdevs.next, struct v4l2_subdev, list);struct i2c_client *client =v4l2_get_subdevdata (sd); -struct resource *reg_res; -if (irq >0 ) -free_irq (irq, vou_dev);pm_runtime_disable (&pdev->dev);video_unregister_device (&vou_dev->vdev);i2c_put_adapter (client->adapter);v4l2_device_unregister (&vou_dev->v4l2_dev); -iounmap (vou_dev->base); - reg_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (reg_res) -release_mem_region (reg_res->start,resource_size (reg_res)); -kfree (vou_dev);return 0 ; }
Signature · 1 line
2.1.0