linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] media: ov2680: don't register the v4l2 subdevice before checking chip ID
@ 2018-09-01 12:46 Javier Martinez Canillas
  2018-09-01 12:46 ` [PATCH v2 2/2] media: ov2680: rename ov2680_v4l2_init() to ov2680_v4l2_register() Javier Martinez Canillas
  0 siblings, 1 reply; 2+ messages in thread
From: Javier Martinez Canillas @ 2018-09-01 12:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sakari Ailus, Javier Martinez Canillas, Mauro Carvalho Chehab,
	Rui Miguel Silva, linux-media

The driver registers the v4l2 subdevice before attempting to power on the
chip and checking its ID. This means that a media device driver that it's
waiting for this subdevice to be bound, will prematurely expose its media
device node to userspace because if something goes wrong the media entity
will be cleaned up again on the ov2680 probe function.

This also simplifies the probe function error path since no initialization
is made before attempting to enable the resources or checking the chip ID.

Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver")
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>

---

Changes in v2:
- Just move ov2680_check_id() before ov2680_v4l2_init() - Suggested by Sakari.

 drivers/media/i2c/ov2680.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index f753a1c333ef..3ccd584568fb 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -1088,26 +1088,20 @@ static int ov2680_probe(struct i2c_client *client)
 
 	mutex_init(&sensor->lock);
 
-	ret = ov2680_v4l2_init(sensor);
+	ret = ov2680_check_id(sensor);
 	if (ret < 0)
 		goto lock_destroy;
 
-	ret = ov2680_check_id(sensor);
+	ret = ov2680_v4l2_init(sensor);
 	if (ret < 0)
-		goto error_cleanup;
+		goto lock_destroy;
 
 	dev_info(dev, "ov2680 init correctly\n");
 
 	return 0;
 
-error_cleanup:
-	dev_err(dev, "ov2680 init fail: %d\n", ret);
-
-	media_entity_cleanup(&sensor->sd.entity);
-	v4l2_async_unregister_subdev(&sensor->sd);
-	v4l2_ctrl_handler_free(&sensor->ctrls.handler);
-
 lock_destroy:
+	dev_err(dev, "ov2680 init fail: %d\n", ret);
 	mutex_destroy(&sensor->lock);
 
 	return ret;
-- 
2.17.1

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

* [PATCH v2 2/2] media: ov2680: rename ov2680_v4l2_init() to ov2680_v4l2_register()
  2018-09-01 12:46 [PATCH v2 1/2] media: ov2680: don't register the v4l2 subdevice before checking chip ID Javier Martinez Canillas
@ 2018-09-01 12:46 ` Javier Martinez Canillas
  0 siblings, 0 replies; 2+ messages in thread
From: Javier Martinez Canillas @ 2018-09-01 12:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sakari Ailus, Javier Martinez Canillas, Mauro Carvalho Chehab,
	Rui Miguel Silva, linux-media

The function not only does initialization but also registers the subdevice
so change its name to make this more clear.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>

---

Changes in v2: None

 drivers/media/i2c/ov2680.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 3ccd584568fb..0e34e15b67b3 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -926,7 +926,7 @@ static int ov2680_mode_init(struct ov2680_dev *sensor)
 	return 0;
 }
 
-static int ov2680_v4l2_init(struct ov2680_dev *sensor)
+static int ov2680_v4l2_register(struct ov2680_dev *sensor)
 {
 	const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops;
 	struct ov2680_ctrls *ctrls = &sensor->ctrls;
@@ -1092,7 +1092,7 @@ static int ov2680_probe(struct i2c_client *client)
 	if (ret < 0)
 		goto lock_destroy;
 
-	ret = ov2680_v4l2_init(sensor);
+	ret = ov2680_v4l2_register(sensor);
 	if (ret < 0)
 		goto lock_destroy;
 
-- 
2.17.1

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

end of thread, other threads:[~2018-09-01 16:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-01 12:46 [PATCH v2 1/2] media: ov2680: don't register the v4l2 subdevice before checking chip ID Javier Martinez Canillas
2018-09-01 12:46 ` [PATCH v2 2/2] media: ov2680: rename ov2680_v4l2_init() to ov2680_v4l2_register() Javier Martinez Canillas

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).