Skip to contentSkip to conversation

media: i2c: rdacm20: Constify static structs

PATCH In review Rikard Falkeborn 3 participants 3 messages Nov 19, 2020 – Nov 20, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: i2c: rdacm20: Constify static structs

The only usage of rdacm20_video_ops is to assign it to the video field in the v4l2_subdev_ops struct which is a pointer to const, and the only usage of rdacm20_subdev_ops is to pass its address to v4l2_i2c_subdev_init() which accepts a pointer to const. Make them const to allow the compiler to put them in read-only memory.

---
 drivers/media/i2c/rdacm20.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/rdacm20.c +2 -2
index 1ed928c4ca70..ac00a6743623 100644
@@ -435,7 +435,7 @@ static int rdacm20_get_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
-static struct v4l2_subdev_video_ops rdacm20_video_ops = {
+static const struct v4l2_subdev_video_ops rdacm20_video_ops = {
 	.s_stream	= rdacm20_s_stream,
 };
 
@@ -445,7 +445,7 @@ static const struct v4l2_subdev_pad_ops rdacm20_subdev_pad_ops = {
 	.set_fmt	= rdacm20_get_fmt,
 };
 
-static struct v4l2_subdev_ops rdacm20_subdev_ops = {
+static const struct v4l2_subdev_ops rdacm20_subdev_ops = {
 	.video		= &rdacm20_video_ops,
 	.pad		= &rdacm20_subdev_pad_ops,
 };
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw

Hi Rikard,

Quoted 7 lines · Rikard Falkeborn

The only usage of rdacm20_video_ops is to assign it to the video field in the v4l2_subdev_ops struct which is a pointer to const, and the only usage of rdacm20_subdev_ops is to pass its address to v4l2_i2c_subdev_init() which accepts a pointer to const. Make them const to allow the compiler to put them in read-only memory.

Thanks

Quoted 29 lines
---
 drivers/media/i2c/rdacm20.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/rdacm20.c +2 -3
index 1ed928c4ca70..ac00a6743623 100644
@@ -435,7 +435,7 @@ static int rdacm20_get_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
-static struct v4l2_subdev_video_ops rdacm20_video_ops = {
+static const struct v4l2_subdev_video_ops rdacm20_video_ops = {
 	.s_stream	= rdacm20_s_stream,
 };
 
@@ -445,7 +445,7 @@ static const struct v4l2_subdev_pad_ops rdacm20_subdev_pad_ops = {
 	.set_fmt	= rdacm20_get_fmt,
 };
 
-static struct v4l2_subdev_ops rdacm20_subdev_ops = {
+static const struct v4l2_subdev_ops rdacm20_subdev_ops = {
 	.video		= &rdacm20_video_ops,
 	.pad		= &rdacm20_subdev_pad_ops,
 };
--

2.29.2

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Rikard Falkeborn

Hi Rikard,

Thank you for the fix.

Quoted 7 lines · Rikard Falkeborn

The only usage of rdacm20_video_ops is to assign it to the video field in the v4l2_subdev_ops struct which is a pointer to const, and the only usage of rdacm20_subdev_ops is to pass its address to v4l2_i2c_subdev_init() which accepts a pointer to const. Make them const to allow the compiler to put them in read-only memory.

Quoted 27 lines
---
 drivers/media/i2c/rdacm20.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/rdacm20.c +2 -2
index 1ed928c4ca70..ac00a6743623 100644
@@ -435,7 +435,7 @@ static int rdacm20_get_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
-static struct v4l2_subdev_video_ops rdacm20_video_ops = {
+static const struct v4l2_subdev_video_ops rdacm20_video_ops = {
 	.s_stream	= rdacm20_s_stream,
 };
 
@@ -445,7 +445,7 @@ static const struct v4l2_subdev_pad_ops rdacm20_subdev_pad_ops = {
 	.set_fmt	= rdacm20_get_fmt,
 };
 
-static struct v4l2_subdev_ops rdacm20_subdev_ops = {
+static const struct v4l2_subdev_ops rdacm20_subdev_ops = {
 	.video		= &rdacm20_video_ops,
 	.pad		= &rdacm20_subdev_pad_ops,
 };