linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <javierm@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Javier Martinez Canillas <javierm@redhat.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Rui Miguel Silva <rmfrfs@gmail.com>,
	linux-media@vger.kernel.org
Subject: [PATCH] media: ov2680: register the v4l2 subdev async at the end of probe
Date: Fri, 31 Aug 2018 17:19:06 +0200	[thread overview]
Message-ID: <20180831151906.9315-1-javierm@redhat.com> (raw)

The driver registers the subdev async in the middle of the probe function
but this has to be done at the very end of the probe function to prevent
registering a device whose probe function could fail (i.e: the clock and
regulators enable can fail, the I2C transfers could return errors, etc).

It could also lead to a media device driver that is waiting to bound the
v4l2 subdevice to incorrectly expose its media device to userspace, since
the subdev is registered but later its media entity is cleaned up on error.

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

---

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

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index f753a1c333ef..2ef920a17278 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -983,10 +983,6 @@ static int ov2680_v4l2_init(struct ov2680_dev *sensor)
 
 	sensor->sd.ctrl_handler = hdl;
 
-	ret = v4l2_async_register_subdev(&sensor->sd);
-	if (ret < 0)
-		goto cleanup_entity;
-
 	return 0;
 
 cleanup_entity:
@@ -1096,6 +1092,10 @@ static int ov2680_probe(struct i2c_client *client)
 	if (ret < 0)
 		goto error_cleanup;
 
+	ret = v4l2_async_register_subdev(&sensor->sd);
+	if (ret < 0)
+		goto error_cleanup;
+
 	dev_info(dev, "ov2680 init correctly\n");
 
 	return 0;
@@ -1104,7 +1104,6 @@ static int ov2680_probe(struct i2c_client *client)
 	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:
-- 
2.17.1


             reply	other threads:[~2018-08-31 15:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-31 15:19 Javier Martinez Canillas [this message]
2018-09-01 11:46 ` [PATCH] media: ov2680: register the v4l2 subdev async at the end of probe Sakari Ailus
2018-09-01 12:37   ` Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180831151906.9315-1-javierm@redhat.com \
    --to=javierm@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rmfrfs@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).