The V4L2 async notifier embedded in the imx_media_dev structure is triggered when the CSI bridge subdev is registered. We don't need an async notifier for this, as we can call the .complete() handler directly from the CSI bridge subdev .registered() handler. Signed-off-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx> --- drivers/staging/media/imx/imx7-media-csi.c | 63 +++++++--------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index e2d6dabad007..984f7bec15af 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -721,11 +721,6 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data) * Temporary copy of imx_media_dev helpers */ -static inline struct imx_media_dev *notifier2dev(struct v4l2_async_notifier *n) -{ - return container_of(n, struct imx_media_dev, notifier); -} - /* * adds given video device to given imx-media source pad vdev list. * Continues upstream from the pad entity's sink pads. @@ -848,9 +843,8 @@ static int imx_media_create_pad_vdev_lists(struct imx_media_dev *imxmd) } /* async subdev complete notifier */ -static int __imx_media_probe_complete(struct v4l2_async_notifier *notifier) +static int __imx_media_probe_complete(struct imx_media_dev *imxmd) { - struct imx_media_dev *imxmd = notifier2dev(notifier); int ret; mutex_lock(&imxmd->mutex); @@ -868,33 +862,6 @@ static int __imx_media_probe_complete(struct v4l2_async_notifier *notifier) return media_device_register(&imxmd->md); } -static const struct v4l2_async_notifier_operations imx_media_notifier_ops = { - .complete = __imx_media_probe_complete, -}; - -static int __imx_media_dev_notifier_register(struct imx_media_dev *imxmd, - const struct v4l2_async_notifier_operations *ops) -{ - int ret; - - /* no subdevs? just bail */ - if (list_empty(&imxmd->notifier.asd_list)) { - v4l2_err(&imxmd->v4l2_dev, "no subdevs\n"); - return -ENODEV; - } - - /* prepare the async subdev notifier and register it */ - imxmd->notifier.ops = ops ? ops : &imx_media_notifier_ops; - ret = v4l2_async_nf_register(&imxmd->v4l2_dev, &imxmd->notifier); - if (ret) { - v4l2_err(&imxmd->v4l2_dev, - "v4l2_async_nf_register failed with %d\n", ret); - return ret; - } - - return 0; -} - /* ----------------------------------------------------------------------------- * V4L2 Subdev Operations */ @@ -1247,10 +1214,12 @@ static int imx7_csi_registered(struct v4l2_subdev *sd) ret = imx_media_capture_device_register(csi->vdev, MEDIA_LNK_FL_IMMUTABLE); - if (ret) + if (ret) { imx_media_capture_device_remove(csi->vdev); + return ret; + } - return ret; + return __imx_media_probe_complete(csi->imxmd); } static void imx7_csi_unregistered(struct v4l2_subdev *sd) @@ -1316,8 +1285,16 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier, MEDIA_LNK_FL_IMMUTABLE); } +static int imx7_csi_notify_complete(struct v4l2_async_notifier *notifier) +{ + struct imx7_csi *csi = imx7_csi_notifier_to_dev(notifier); + + return v4l2_device_register_subdev_nodes(&csi->imxmd->v4l2_dev); +} + static const struct v4l2_async_notifier_operations imx7_csi_notify_ops = { .bound = imx7_csi_notify_bound, + .complete = imx7_csi_notify_complete, }; static int imx7_csi_async_register(struct imx7_csi *csi) @@ -1346,11 +1323,11 @@ static int imx7_csi_async_register(struct imx7_csi *csi) csi->notifier.ops = &imx7_csi_notify_ops; - ret = v4l2_async_subdev_nf_register(&csi->sd, &csi->notifier); + ret = v4l2_async_nf_register(&csi->imxmd->v4l2_dev, &csi->notifier); if (ret) return ret; - return v4l2_async_register_subdev(&csi->sd); + return 0; } static void imx7_csi_media_cleanup(struct imx7_csi *csi) @@ -1378,12 +1355,6 @@ static int imx7_csi_media_init(struct imx7_csi *csi) return ret; } - ret = __imx_media_dev_notifier_register(imxmd, NULL); - if (ret < 0) { - imx7_csi_media_cleanup(csi); - return ret; - } - csi->imxmd = imxmd; return 0; @@ -1458,6 +1429,10 @@ static int imx7_csi_probe(struct platform_device *pdev) if (ret < 0) goto cleanup; + ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd); + if (ret) + goto cleanup; + ret = imx7_csi_async_register(csi); if (ret) goto subdev_notifier_cleanup; -- Regards, Laurent Pinchart