media: ov9650: remove unnecessary terminated entry in menu items array
Akinobu Mita
reviewerPATCH 1/1 media: ov9650: remove unnecessary terminated entry in menu items array
The test_pattern_menu[] array has two valid items and a null terminated item. So the control's maximum value which is passed to v4l2_ctrl_new_std_menu_items() should be one. However, 'ARRAY_SIZE(test_pattern_menu) - 1' is actually passed and it's not correct.
Fix it by removing unnecessary terminated entry and let the correct control's maximum value be passed to v4l2_ctrl_new_std_menu_items().
--- drivers/media/i2c/ov9650.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/i2c/ov9650.c +0 -1
@@ -985,7 +985,6 @@ static const struct v4l2_ctrl_ops ov965x_ctrl_ops = {static const char *const test_pattern_menu[] = {"Disabled" ,"Color bars" , -NULL };static int ov965x_initialize_controls (struct ov965x *ov965x)
Signature · 1 line
2.7.4
Quoted 21 lines · Akinobu Mita
The test_pattern_menu[] array has two valid items and a null terminated item. So the control's maximum value which is passed to
v4l2_ctrl_new_std_menu_items()should be one. However, 'ARRAY_SIZE(test_pattern_menu)- 1' is actually passed and it's not correct.Fix it by removing unnecessary terminated entry and let the correct control's maximum value be passed to
v4l2_ctrl_new_std_menu_items().Cc Sylwester Nawrocki <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Signed-off-by Akinobu Mita <[email protected]>--- drivers/media/i2c/ov9650.c | 1 - 1 file changed, 1 deletion(-)drivers/media/i2c/ov9650.c +0
-0
drivers/media/i2c/ov9650.c static const struct v4l2_ctrl_ops ov965x_ctrl_ops = { · line 988
Quoted 4 lines
drivers/media/i2c/ov9650.c +0
-1@@ -985,7 +985,6 @@ static const struct v4l2_ctrl_ops ov965x_ctrl_ops = {static const char *const test_pattern_menu[] = {"Disabled" ,"Color bars" , -NULL
The number of items in the menu changes; I fixed that while applying the patch:
drivers/media/i2c/ov9650.c +1 -1
@@ -1039,7 +1039,7 @@ static int ov965x_initialize_controls(struct ov965x *ov965x) V4L2_CID_POWER_LINE_FREQUENCY_50HZ);v4l2_ctrl_new_std_menu_items (hdl, ops,V4L2_CID_TEST_PATTERN , -ARRAY_SIZE (test_pattern_menu) -1 ,0 ,0 , +ARRAY_SIZE (test_pattern_menu),0 ,0 , test_pattern_menu);if (hdl->error) { ret = hdl->error;
Let me know if you see issues with this.
Quoted 3 lines
drivers/media/i2c/ov9650.c +0
-0};static int ov965x_initialize_controls (struct ov965x *ov965x)
Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected]
Akinobu Mita
reviewerHi Sakari,
2017-10-25 19:23 GMT+09:00 Sakari Ailus <[email protected]>:
Quoted 45 lines · Akinobu Mita
Quoted 21 lines
The test_pattern_menu[] array has two valid items and a null terminated item. So the control's maximum value which is passed to
v4l2_ctrl_new_std_menu_items()should be one. However, 'ARRAY_SIZE(test_pattern_menu)- 1' is actually passed and it's not correct.Fix it by removing unnecessary terminated entry and let the correct control's maximum value be passed to
v4l2_ctrl_new_std_menu_items().Cc Sylwester Nawrocki <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Signed-off-by Akinobu Mita <[email protected]>--- drivers/media/i2c/ov9650.c | 1 - 1 file changed, 1 deletion(-)drivers/media/i2c/ov9650.c +0
-0drivers/media/i2c/ov9650.c static const struct v4l2_ctrl_ops ov965x_ctrl_ops = { · line 988
Quoted 4 lines
drivers/media/i2c/ov9650.c +0
-1@@ -985,7 +985,6 @@ static const struct v4l2_ctrl_ops ov965x_ctrl_ops = {static const char *const test_pattern_menu[] = {"Disabled" ,"Color bars" , -NULL The number of items in the menu changes; I fixed that while applying the patch:
drivers/media/i2c/ov9650.c +1
-1@@ -1039,7 +1039,7 @@ static int ov965x_initialize_controls(struct ov965x *ov965x) V4L2_CID_POWER_LINE_FREQUENCY_50HZ);v4l2_ctrl_new_std_menu_items (hdl, ops,V4L2_CID_TEST_PATTERN , -ARRAY_SIZE (test_pattern_menu) -1 ,0 ,0 , +ARRAY_SIZE (test_pattern_menu),0 ,0 , test_pattern_menu);if (hdl->error) { ret = hdl->error;
Quoted 1 line
Let me know if you see issues with this.
This change actually causes an issue.
This problem was found when I got the list of available controls for ov9650 subdev.
$ yavta -l /dev/v4l-subdev0 <...> --- Image Processing Controls (class 0x009f0001) --- control 0x009f0903 `Test Pattern' min 0 max 2 step 1 default 0 current 0. 0: Disabled (*) 1: Color bars
Strangely, the max control value is '2'. So I tried to set the control to '2' for the fun and got a null pointer dereference.
$ yavta -w '0x009f0903 2' --no-query /dev/v4l-subdev0 Device /dev/v4l-subdev0 opened. Segmentation fault
Then, I found that the root cause is unnecessary terminated entry. So 'ARRAY_SIZE(test_pattern_menu) - 1' (=1) should be passed to v4l2_ctrl_new_std_menu_items().
Quoted 65 lines · Akinobu Mita
Hi Sakari,
2017-10-25 19:23 GMT+09:00 Sakari Ailus <[email protected]>:
Quoted 45 lines · Akinobu Mita
Quoted 21 lines
The test_pattern_menu[] array has two valid items and a null terminated item. So the control's maximum value which is passed to
v4l2_ctrl_new_std_menu_items()should be one. However, 'ARRAY_SIZE(test_pattern_menu)- 1' is actually passed and it's not correct.Fix it by removing unnecessary terminated entry and let the correct control's maximum value be passed to
v4l2_ctrl_new_std_menu_items().Cc Sylwester Nawrocki <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Signed-off-by Akinobu Mita <[email protected]>--- drivers/media/i2c/ov9650.c | 1 - 1 file changed, 1 deletion(-)drivers/media/i2c/ov9650.c +0
-0drivers/media/i2c/ov9650.c static const struct v4l2_ctrl_ops ov965x_ctrl_ops = { · line 988
Quoted 4 lines
drivers/media/i2c/ov9650.c +0
-1@@ -985,7 +985,6 @@ static const struct v4l2_ctrl_ops ov965x_ctrl_ops = {static const char *const test_pattern_menu[] = {"Disabled" ,"Color bars" , -NULL The number of items in the menu changes; I fixed that while applying the patch:
drivers/media/i2c/ov9650.c +1
-1@@ -1039,7 +1039,7 @@ static int ov965x_initialize_controls(struct ov965x *ov965x) V4L2_CID_POWER_LINE_FREQUENCY_50HZ);v4l2_ctrl_new_std_menu_items (hdl, ops,V4L2_CID_TEST_PATTERN , -ARRAY_SIZE (test_pattern_menu) -1 ,0 ,0 , +ARRAY_SIZE (test_pattern_menu),0 ,0 , test_pattern_menu);if (hdl->error) { ret = hdl->error;Quoted 1 line
Let me know if you see issues with this.
This change actually causes an issue.
This problem was found when I got the list of available controls for ov9650 subdev.
$ yavta -l /dev/v4l-subdev0 <...> --- Image Processing Controls (class 0x009f0001) --- control 0x009f0903 `Test Pattern' min 0 max 2 step 1 default 0 current 0. 0: Disabled (*) 1: Color barsStrangely, the max control value is '2'. So I tried to set the control to '2' for the fun and got a null pointer dereference.
Quoted 7 lines
$ yavta -w '0x009f0903 2' --no-query /dev/v4l-subdev0 Device /dev/v4l-subdev0 opened. Segmentation faultThen, I found that the root cause is unnecessary terminated entry. So '
ARRAY_SIZE(test_pattern_menu)- 1' (=1) should be passed tov4l2_ctrl_new_std_menu_items().
Oops. Indeed, I'll drop that change above.
Thanks!
Signature · 2 lines
Sakari Ailus e-mail: [email protected]