From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Hans Verkuil <hverkuil@xs4all.nl>,
linux-media@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
tomoharu.fukawa.eb@renesas.com,
"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Subject: [PATCH v2 15/17] rcar-vin: register the video device at probe time
Date: Wed, 24 May 2017 02:15:38 +0200 [thread overview]
Message-ID: <20170524001540.13613-16-niklas.soderlund@ragnatech.se> (raw)
In-Reply-To: <20170524001540.13613-1-niklas.soderlund@ragnatech.se>
From: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
The driver registers the video device from the async complete callback
and unregistered in the async unbind callback. This creates problems if
if the subdevice is bound, unbound and later rebound. The second time
video_register_device() is called it fails:
kobject (eb3be918): tried to init an initialized object, something is seriously wrong.
To prevent this register the video device at prob time and don't allow
user-space to open the video device if the subdevice have not yet been
bound.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
drivers/media/platform/rcar-vin/rcar-core.c | 47 ++++++++++++++++++++++++++---
drivers/media/platform/rcar-vin/rcar-v4l2.c | 42 ++++----------------------
drivers/media/platform/rcar-vin/rcar-vin.h | 1 +
3 files changed, 50 insertions(+), 40 deletions(-)
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c
index dcca906ba58435f5..0e1757301a0bca1e 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -74,6 +74,7 @@ static bool rvin_mbus_supported(struct rvin_graph_entity *entity)
static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
{
struct rvin_dev *vin = notifier_to_vin(notifier);
+ struct v4l2_subdev *sd = vin_to_source(vin);
int ret;
/* Verify subdevices mbus format */
@@ -92,7 +93,35 @@ static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
return ret;
}
- return rvin_v4l2_probe(vin);
+ /* Add the controls */
+ /*
+ * Currently the subdev with the largest number of controls (13) is
+ * ov6550. So let's pick 16 as a hint for the control handler. Note
+ * that this is a hint only: too large and you waste some memory, too
+ * small and there is a (very) small performance hit when looking up
+ * controls in the internal hash.
+ */
+ ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
+ if (ret < 0)
+ return ret;
+
+ ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, sd->ctrl_handler, NULL);
+ if (ret < 0)
+ return ret;
+
+ ret = v4l2_subdev_call(sd, video, g_tvnorms, &vin->vdev.tvnorms);
+ if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
+ return ret;
+
+ if (vin->vdev.tvnorms == 0) {
+ /* Disable the STD API if there are no tvnorms defined */
+ v4l2_disable_ioctl(&vin->vdev, VIDIOC_G_STD);
+ v4l2_disable_ioctl(&vin->vdev, VIDIOC_S_STD);
+ v4l2_disable_ioctl(&vin->vdev, VIDIOC_QUERYSTD);
+ v4l2_disable_ioctl(&vin->vdev, VIDIOC_ENUMSTD);
+ }
+
+ return rvin_reset_format(vin);
}
static void rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier,
@@ -102,7 +131,7 @@ static void rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier,
struct rvin_dev *vin = notifier_to_vin(notifier);
vin_dbg(vin, "unbind digital subdev %s\n", subdev->name);
- rvin_v4l2_remove(vin);
+ v4l2_ctrl_handler_free(&vin->ctrl_handler);
vin->digital.subdev = NULL;
}
@@ -290,9 +319,13 @@ static int rcar_vin_probe(struct platform_device *pdev)
if (ret)
return ret;
+ ret = rvin_v4l2_probe(vin);
+ if (ret)
+ goto error_dma;
+
ret = rvin_digital_graph_init(vin);
if (ret < 0)
- goto error;
+ goto error_v4l2;
pm_suspend_ignore_children(&pdev->dev, true);
pm_runtime_enable(&pdev->dev);
@@ -300,7 +333,9 @@ static int rcar_vin_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, vin);
return 0;
-error:
+error_v4l2:
+ rvin_v4l2_remove(vin);
+error_dma:
rvin_dma_remove(vin);
return ret;
@@ -314,6 +349,10 @@ static int rcar_vin_remove(struct platform_device *pdev)
v4l2_async_notifier_unregister(&vin->notifier);
+ /* Checks internaly if handlers have been init or not */
+ v4l2_ctrl_handler_free(&vin->ctrl_handler);
+
+ rvin_v4l2_remove(vin);
rvin_dma_remove(vin);
return 0;
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index be6f41bf82ac3bc5..6f1c27fc828fe57e 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -103,7 +103,7 @@ static void rvin_reset_crop_compose(struct rvin_dev *vin)
vin->compose.height = vin->format.height;
}
-static int rvin_reset_format(struct rvin_dev *vin)
+int rvin_reset_format(struct rvin_dev *vin)
{
struct v4l2_subdev_format fmt = {
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
@@ -785,6 +785,11 @@ static int rvin_open(struct file *file)
mutex_lock(&vin->lock);
+ if (!vin->digital.subdev) {
+ ret = -ENODEV;
+ goto unlock;
+ }
+
file->private_data = vin;
ret = v4l2_fh_open(file);
@@ -848,9 +853,6 @@ void rvin_v4l2_remove(struct rvin_dev *vin)
v4l2_info(&vin->v4l2_dev, "Removing %s\n",
video_device_node_name(&vin->vdev));
- /* Checks internaly if handlers have been init or not */
- v4l2_ctrl_handler_free(&vin->ctrl_handler);
-
/* Checks internaly if vdev have been init or not */
video_unregister_device(&vin->vdev);
}
@@ -873,41 +875,10 @@ static void rvin_notify(struct v4l2_subdev *sd,
int rvin_v4l2_probe(struct rvin_dev *vin)
{
struct video_device *vdev = &vin->vdev;
- struct v4l2_subdev *sd = vin_to_source(vin);
int ret;
- v4l2_set_subdev_hostdata(sd, vin);
-
vin->v4l2_dev.notify = rvin_notify;
- ret = v4l2_subdev_call(sd, video, g_tvnorms, &vin->vdev.tvnorms);
- if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
- return ret;
-
- if (vin->vdev.tvnorms == 0) {
- /* Disable the STD API if there are no tvnorms defined */
- v4l2_disable_ioctl(&vin->vdev, VIDIOC_G_STD);
- v4l2_disable_ioctl(&vin->vdev, VIDIOC_S_STD);
- v4l2_disable_ioctl(&vin->vdev, VIDIOC_QUERYSTD);
- v4l2_disable_ioctl(&vin->vdev, VIDIOC_ENUMSTD);
- }
-
- /* Add the controls */
- /*
- * Currently the subdev with the largest number of controls (13) is
- * ov6550. So let's pick 16 as a hint for the control handler. Note
- * that this is a hint only: too large and you waste some memory, too
- * small and there is a (very) small performance hit when looking up
- * controls in the internal hash.
- */
- ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
- if (ret < 0)
- return ret;
-
- ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, sd->ctrl_handler, NULL);
- if (ret < 0)
- return ret;
-
/* video node */
vdev->fops = &rvin_fops;
vdev->v4l2_dev = &vin->v4l2_dev;
@@ -921,7 +892,6 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
V4L2_CAP_READWRITE;
vin->format.pixelformat = RVIN_DEFAULT_FORMAT;
- rvin_reset_format(vin);
ret = video_register_device(&vin->vdev, VFL_TYPE_GRABBER, -1);
if (ret) {
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h
index 9bfb5a7c4dc4f215..9d0d4a5001b6ccd8 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -158,6 +158,7 @@ void rvin_dma_remove(struct rvin_dev *vin);
int rvin_v4l2_probe(struct rvin_dev *vin);
void rvin_v4l2_remove(struct rvin_dev *vin);
+int rvin_reset_format(struct rvin_dev *vin);
const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
--
2.13.0
next prev parent reply other threads:[~2017-05-24 0:17 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-24 0:15 [PATCH v2 00/17] rcar-vin: fix issues with format and capturing Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 01/17] rcar-vin: reset bytesperline and sizeimage when resetting format Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 02/17] rcar-vin: use rvin_reset_format() in S_DV_TIMINGS Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 03/17] rcar-vin: fix how pads are handled for v4l2 subdevice operations Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 04/17] rcar-vin: fix standard in input enumeration Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 05/17] rcar-vin: move subdev source and sink pad index to rvin_graph_entity Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 06/17] rcar-vin: refactor pad lookup code Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 07/17] rcar-vin: move pad lookup to async bound handler Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 08/17] rcar-vin: use pad information when verifying media bus format Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 09/17] rcar-vin: decrease buffers needed to capture Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 10/17] rcar-vin: move functions which acts on hardware Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 11/17] rcar-vin: select capture mode based on free buffers Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 12/17] rcar-vin: allow switch between capturing modes when stalling Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 13/17] rcar-vin: refactor and fold in function after stall handling rework Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 14/17] rcar-vin: remove subdevice matching from bind and unbind callbacks Niklas Söderlund
2017-05-24 0:15 ` Niklas Söderlund [this message]
2017-05-29 6:52 ` [PATCH v2 15/17] rcar-vin: register the video device at probe time Hans Verkuil
2017-05-29 6:56 ` Hans Verkuil
2017-05-29 7:49 ` Niklas Söderlund
2017-05-29 7:55 ` Hans Verkuil
2017-05-29 8:13 ` Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 16/17] rcar-vin: add missing error check to propagate error Niklas Söderlund
2017-05-24 0:15 ` [PATCH v2 17/17] rcar-vin: fix bug in pixelformat selection Niklas Söderlund
2017-05-24 9:01 ` Sergei Shtylyov
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=20170524001540.13613-16-niklas.soderlund@ragnatech.se \
--to=niklas.soderlund@ragnatech.se \
--cc=hverkuil@xs4all.nl \
--cc=kieran.bingham@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=sakari.ailus@linux.intel.com \
--cc=tomoharu.fukawa.eb@renesas.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).