diff mbox

drivers: media: i2c: mt9t001: constify v4l2_subdev_* structures

Message ID 1481445326-19864-1-git-send-email-bhumirks@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bhumika Goyal Dec. 11, 2016, 8:35 a.m. UTC
v4l2_subdev_{core/pad/video}_ops structures are stored in the 
fields of the v4l2_subdev_ops structure which are of
type const. Also, v4l2_subdev_ops structure is passed to a function 
having its argument of type const. As these structures are never 
modified, so declare them as const.
Done using Coccinelle: (One of the scripts used)

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct v4l2_subdev_ops i@p = {...};

@ok1@
identifier r1.i;
position p;
expression e1,e2;
@@
v4l2_i2c_subdev_init(e1,e2,&i@p)

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct v4l2_subdev_ops i;

File size before:
   text	   data	    bss	    dec	    hex	filename
   6119	    736	     16	   6871	   1ad7	drivers/media/i2c/mt9t001.o

File size after:
   text	   data	    bss	    dec	    hex	filename
   6631	    232	     16	   6879	   1adf	drivers/media/i2c/mt9t001.o

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
 drivers/media/i2c/mt9t001.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart Dec. 12, 2016, 8:51 a.m. UTC | #1
Hi Bhumika,

Thank you for the patch

On Sunday 11 Dec 2016 14:05:26 Bhumika Goyal wrote:
> v4l2_subdev_{core/pad/video}_ops structures are stored in the
> fields of the v4l2_subdev_ops structure which are of
> type const. Also, v4l2_subdev_ops structure is passed to a function
> having its argument of type const. As these structures are never
> modified, so declare them as const.
> Done using Coccinelle: (One of the scripts used)
> 
> @r1 disable optional_qualifier @
> identifier i;
> position p;
> @@
> static struct v4l2_subdev_ops i@p = {...};
> 
> @ok1@
> identifier r1.i;
> position p;
> expression e1,e2;
> @@
> v4l2_i2c_subdev_init(e1,e2,&i@p)
> 
> @bad@
> position p!={r1.p,ok1.p};
> identifier r1.i;
> @@
> i@p
> 
> @depends on !bad disable optional_qualifier@
> identifier r1.i;
> @@
> +const
> struct v4l2_subdev_ops i;
> 
> File size before:
>    text	   data	    bss	    dec	    hex	filename
>    6119	    736	     16	   6871	   1ad7	drivers/media/i2c/mt9t001.o
> 
> File size after:
>    text	   data	    bss	    dec	    hex	filename
>    6631	    232	     16	   6879	   1adf	drivers/media/i2c/mt9t001.o
> 
> Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/i2c/mt9t001.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/i2c/mt9t001.c b/drivers/media/i2c/mt9t001.c
> index 842017f..9d981d9 100644
> --- a/drivers/media/i2c/mt9t001.c
> +++ b/drivers/media/i2c/mt9t001.c
> @@ -822,15 +822,15 @@ static int mt9t001_close(struct v4l2_subdev *subdev,
> struct v4l2_subdev_fh *fh) return mt9t001_set_power(subdev, 0);
>  }
> 
> -static struct v4l2_subdev_core_ops mt9t001_subdev_core_ops = {
> +static const struct v4l2_subdev_core_ops mt9t001_subdev_core_ops = {
>  	.s_power = mt9t001_set_power,
>  };
> 
> -static struct v4l2_subdev_video_ops mt9t001_subdev_video_ops = {
> +static const struct v4l2_subdev_video_ops mt9t001_subdev_video_ops = {
>  	.s_stream = mt9t001_s_stream,
>  };
> 
> -static struct v4l2_subdev_pad_ops mt9t001_subdev_pad_ops = {
> +static const struct v4l2_subdev_pad_ops mt9t001_subdev_pad_ops = {
>  	.enum_mbus_code = mt9t001_enum_mbus_code,
>  	.enum_frame_size = mt9t001_enum_frame_size,
>  	.get_fmt = mt9t001_get_format,
> @@ -839,7 +839,7 @@ static int mt9t001_close(struct v4l2_subdev *subdev,
> struct v4l2_subdev_fh *fh) .set_selection = mt9t001_set_selection,
>  };
> 
> -static struct v4l2_subdev_ops mt9t001_subdev_ops = {
> +static const struct v4l2_subdev_ops mt9t001_subdev_ops = {
>  	.core = &mt9t001_subdev_core_ops,
>  	.video = &mt9t001_subdev_video_ops,
>  	.pad = &mt9t001_subdev_pad_ops,
diff mbox

Patch

diff --git a/drivers/media/i2c/mt9t001.c b/drivers/media/i2c/mt9t001.c
index 842017f..9d981d9 100644
--- a/drivers/media/i2c/mt9t001.c
+++ b/drivers/media/i2c/mt9t001.c
@@ -822,15 +822,15 @@  static int mt9t001_close(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
 	return mt9t001_set_power(subdev, 0);
 }
 
-static struct v4l2_subdev_core_ops mt9t001_subdev_core_ops = {
+static const struct v4l2_subdev_core_ops mt9t001_subdev_core_ops = {
 	.s_power = mt9t001_set_power,
 };
 
-static struct v4l2_subdev_video_ops mt9t001_subdev_video_ops = {
+static const struct v4l2_subdev_video_ops mt9t001_subdev_video_ops = {
 	.s_stream = mt9t001_s_stream,
 };
 
-static struct v4l2_subdev_pad_ops mt9t001_subdev_pad_ops = {
+static const struct v4l2_subdev_pad_ops mt9t001_subdev_pad_ops = {
 	.enum_mbus_code = mt9t001_enum_mbus_code,
 	.enum_frame_size = mt9t001_enum_frame_size,
 	.get_fmt = mt9t001_get_format,
@@ -839,7 +839,7 @@  static int mt9t001_close(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
 	.set_selection = mt9t001_set_selection,
 };
 
-static struct v4l2_subdev_ops mt9t001_subdev_ops = {
+static const struct v4l2_subdev_ops mt9t001_subdev_ops = {
 	.core = &mt9t001_subdev_core_ops,
 	.video = &mt9t001_subdev_video_ops,
 	.pad = &mt9t001_subdev_pad_ops,