media: rcar-vin: Register media device when all sub-devices bound
authorNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Thu, 13 Aug 2020 21:06:02 +0000 (23:06 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sat, 29 Aug 2020 06:16:58 +0000 (08:16 +0200)
The media device is not usable by userspace before all devices involved
in capture are present in the system. Move registering of the media
device to the async complete callback.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/rcar-vin/rcar-core.c

index 1cbbcc9..04c9b33 100644 (file)
@@ -243,7 +243,6 @@ static struct rvin_group *rvin_group_data;
 
 static void rvin_group_cleanup(struct rvin_group *group)
 {
-       media_device_unregister(&group->mdev);
        media_device_cleanup(&group->mdev);
        mutex_destroy(&group->lock);
 }
@@ -253,7 +252,6 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin)
        struct media_device *mdev = &group->mdev;
        const struct of_device_id *match;
        struct device_node *np;
-       int ret;
 
        mutex_init(&group->lock);
 
@@ -278,11 +276,7 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin)
 
        media_device_init(mdev);
 
-       ret = media_device_register(&group->mdev);
-       if (ret)
-               rvin_group_cleanup(group);
-
-       return ret;
+       return 0;
 }
 
 static void rvin_group_release(struct kref *kref)
@@ -682,6 +676,10 @@ static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier)
        unsigned int i;
        int ret;
 
+       ret = media_device_register(&vin->group->mdev);
+       if (ret)
+               return ret;
+
        ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev);
        if (ret) {
                vin_err(vin, "Failed to register subdev nodes\n");
@@ -762,6 +760,8 @@ static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier,
        }
 
        mutex_unlock(&vin->group->lock);
+
+       media_device_unregister(&vin->group->mdev);
 }
 
 static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier,