linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Random ov7740 fixes
@ 2018-04-12 10:21 Sakari Ailus
  2018-04-12 10:21 ` [PATCH 1/4] ov7740: Fix number of controls hint Sakari Ailus
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Sakari Ailus @ 2018-04-12 10:21 UTC (permalink / raw)
  To: linux-media; +Cc: Wenyou Yang

Hi folks,

I wrote these fixes to the ov7740 driver for the problems I saw. Mostly
error handling as well as setting the events flag to enable control
events.

Sakari Ailus (4):
  ov7740: Fix number of controls hint
  ov7740: Check for possible NULL return value in control creation
  ov7740: Fix control handler error at the end of control init
  ov7740: Set subdev HAS_EVENT flag

 drivers/media/i2c/ov7740.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] ov7740: Fix number of controls hint
  2018-04-12 10:21 [PATCH 0/4] Random ov7740 fixes Sakari Ailus
@ 2018-04-12 10:21 ` Sakari Ailus
  2018-04-12 10:21 ` [PATCH 2/4] ov7740: Check for possible NULL return value in control creation Sakari Ailus
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2018-04-12 10:21 UTC (permalink / raw)
  To: linux-media; +Cc: Wenyou Yang

The driver has 12 controls, not 2.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/ov7740.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index 01f578785e79..c9b8bec6373f 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -953,7 +953,7 @@ static int ov7740_init_controls(struct ov7740 *ov7740)
 	struct v4l2_ctrl_handler *ctrl_hdlr = &ov7740->ctrl_handler;
 	int ret;
 
-	ret = v4l2_ctrl_handler_init(ctrl_hdlr, 2);
+	ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12);
 	if (ret < 0)
 		return ret;
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] ov7740: Check for possible NULL return value in control creation
  2018-04-12 10:21 [PATCH 0/4] Random ov7740 fixes Sakari Ailus
  2018-04-12 10:21 ` [PATCH 1/4] ov7740: Fix number of controls hint Sakari Ailus
@ 2018-04-12 10:21 ` Sakari Ailus
  2018-04-12 10:21 ` [PATCH 3/4] ov7740: Fix control handler error at the end of control init Sakari Ailus
  2018-04-12 10:21 ` [PATCH 4/4] ov7740: Set subdev HAS_EVENT flag Sakari Ailus
  3 siblings, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2018-04-12 10:21 UTC (permalink / raw)
  To: linux-media; +Cc: Wenyou Yang

Check that creating the control actually succeeded before accessing it.
A failure would lead to NULL pointer reference. Fix this.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/ov7740.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index c9b8bec6373f..cbfa5a3327f6 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -980,21 +980,26 @@ static int ov7740_init_controls(struct ov7740 *ov7740)
 					V4L2_CID_HFLIP, 0, 1, 1, 0);
 	ov7740->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
 					V4L2_CID_VFLIP, 0, 1, 1, 0);
+
 	ov7740->gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
 				       V4L2_CID_GAIN, 0, 1023, 1, 500);
+	if (ov7740->gain)
+		ov7740->gain->flags |= V4L2_CTRL_FLAG_VOLATILE;
+
 	ov7740->auto_gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
 					    V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
+
 	ov7740->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops,
 					   V4L2_CID_EXPOSURE, 0, 65535, 1, 500);
+	if (ov7740->exposure)
+		ov7740->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE;
+
 	ov7740->auto_exposure = v4l2_ctrl_new_std_menu(ctrl_hdlr,
 					&ov7740_ctrl_ops,
 					V4L2_CID_EXPOSURE_AUTO,
 					V4L2_EXPOSURE_MANUAL, 0,
 					V4L2_EXPOSURE_AUTO);
 
-	ov7740->gain->flags |= V4L2_CTRL_FLAG_VOLATILE;
-	ov7740->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE;
-
 	v4l2_ctrl_auto_cluster(3, &ov7740->auto_wb, 0, false);
 	v4l2_ctrl_auto_cluster(2, &ov7740->auto_gain, 0, true);
 	v4l2_ctrl_auto_cluster(2, &ov7740->auto_exposure,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] ov7740: Fix control handler error at the end of control init
  2018-04-12 10:21 [PATCH 0/4] Random ov7740 fixes Sakari Ailus
  2018-04-12 10:21 ` [PATCH 1/4] ov7740: Fix number of controls hint Sakari Ailus
  2018-04-12 10:21 ` [PATCH 2/4] ov7740: Check for possible NULL return value in control creation Sakari Ailus
@ 2018-04-12 10:21 ` Sakari Ailus
  2018-04-12 10:30   ` [PATCH v1.1 " Sakari Ailus
  2018-04-12 10:21 ` [PATCH 4/4] ov7740: Set subdev HAS_EVENT flag Sakari Ailus
  3 siblings, 1 reply; 6+ messages in thread
From: Sakari Ailus @ 2018-04-12 10:21 UTC (permalink / raw)
  To: linux-media; +Cc: Wenyou Yang

Check that no error happened during adding controls to the driver's
control handler. Print an error message and bail out if there was one.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/ov7740.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index cbfa5a3327f6..0c15b67f3c34 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -1000,6 +1000,13 @@ static int ov7740_init_controls(struct ov7740 *ov7740)
 					V4L2_EXPOSURE_MANUAL, 0,
 					V4L2_EXPOSURE_AUTO);
 
+	if (ctrl_hdlr->error) {
+		ret = ctrl_hdlr->error;
+		dev_err(&client->dev, "controls initialisation failed (%d)\n",
+			ret);
+		goto error;
+	}
+
 	v4l2_ctrl_auto_cluster(3, &ov7740->auto_wb, 0, false);
 	v4l2_ctrl_auto_cluster(2, &ov7740->auto_gain, 0, true);
 	v4l2_ctrl_auto_cluster(2, &ov7740->auto_exposure,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] ov7740: Set subdev HAS_EVENT flag
  2018-04-12 10:21 [PATCH 0/4] Random ov7740 fixes Sakari Ailus
                   ` (2 preceding siblings ...)
  2018-04-12 10:21 ` [PATCH 3/4] ov7740: Fix control handler error at the end of control init Sakari Ailus
@ 2018-04-12 10:21 ` Sakari Ailus
  3 siblings, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2018-04-12 10:21 UTC (permalink / raw)
  To: linux-media; +Cc: Wenyou Yang

The driver has event support implemented but fails to set the flag
enabling event support. Set the flag to enable control events.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/ov7740.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index 0c15b67f3c34..7cba0208b6ee 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -1086,7 +1086,7 @@ static int ov7740_probe(struct i2c_client *client,
 
 #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
 	sd->internal_ops = &ov7740_subdev_internal_ops;
-	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
 #endif
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1.1 3/4] ov7740: Fix control handler error at the end of control init
  2018-04-12 10:21 ` [PATCH 3/4] ov7740: Fix control handler error at the end of control init Sakari Ailus
@ 2018-04-12 10:30   ` Sakari Ailus
  0 siblings, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2018-04-12 10:30 UTC (permalink / raw)
  To: linux-media; +Cc: Wenyou Yang

Check that no error happened during adding controls to the driver's
control handler. Print an error message and bail out if there was one.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
since v1:

- Move error checking after clustering. While clustering won't cause an
  error now, it's better to check for errors only when everything has been
  done.

 drivers/media/i2c/ov7740.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index cbfa5a3327f6..3dad33c6180f 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -1006,6 +1006,13 @@ static int ov7740_init_controls(struct ov7740 *ov7740)
 			       V4L2_EXPOSURE_MANUAL, false);
 	v4l2_ctrl_cluster(2, &ov7740->hflip);
 
+	if (ctrl_hdlr->error) {
+		ret = ctrl_hdlr->error;
+		dev_err(&client->dev, "controls initialisation failed (%d)\n",
+			ret);
+		goto error;
+	}
+
 	ret = v4l2_ctrl_handler_setup(ctrl_hdlr);
 	if (ret) {
 		dev_err(&client->dev, "%s control init failed (%d)\n",
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-04-12 10:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-12 10:21 [PATCH 0/4] Random ov7740 fixes Sakari Ailus
2018-04-12 10:21 ` [PATCH 1/4] ov7740: Fix number of controls hint Sakari Ailus
2018-04-12 10:21 ` [PATCH 2/4] ov7740: Check for possible NULL return value in control creation Sakari Ailus
2018-04-12 10:21 ` [PATCH 3/4] ov7740: Fix control handler error at the end of control init Sakari Ailus
2018-04-12 10:30   ` [PATCH v1.1 " Sakari Ailus
2018-04-12 10:21 ` [PATCH 4/4] ov7740: Set subdev HAS_EVENT flag Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).