media: rkisp1: Use fwnode_graph_for_each_endpoint
authorPaul Elder <paul.elder@ideasonboard.com>
Tue, 14 Jun 2022 19:11:14 +0000 (20:11 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sun, 17 Jul 2022 11:32:16 +0000 (12:32 +0100)
When registering the notifier, replace the manual while loop with
fwnode_graph_for_each_endpoint. This simplifies error handling.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Dafna Hirschfeld <dafna@fastmail.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c

index c3a7ab70bbef0187c86985b42c7a85599cf7b7a8..0eb37ba557cecf7154a2cef86f16de2f81d105b2 100644 (file)
@@ -168,29 +168,28 @@ static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops =
 static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1)
 {
        struct v4l2_async_notifier *ntf = &rkisp1->notifier;
-       unsigned int next_id = 0;
+       struct fwnode_handle *fwnode = dev_fwnode(rkisp1->dev);
+       struct fwnode_handle *ep;
        unsigned int index = 0;
-       int ret;
+       int ret = 0;
 
        v4l2_async_nf_init(ntf);
 
-       while (1) {
+       ntf->ops = &rkisp1_subdev_notifier_ops;
+
+       fwnode_graph_for_each_endpoint(fwnode, ep) {
                struct v4l2_fwnode_endpoint vep = {
                        .bus_type = V4L2_MBUS_CSI2_DPHY
                };
                struct rkisp1_sensor_async *rk_asd;
-               struct fwnode_handle *source = NULL;
-               struct fwnode_handle *ep;
-
-               ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(rkisp1->dev),
-                                                    0, next_id,
-                                                    FWNODE_GRAPH_ENDPOINT_NEXT);
-               if (!ep)
-                       break;
+               struct fwnode_handle *source;
 
                ret = v4l2_fwnode_endpoint_parse(ep, &vep);
-               if (ret)
-                       goto err_parse;
+               if (ret) {
+                       dev_err(rkisp1->dev, "failed to parse endpoint %pfw\n",
+                               ep);
+                       break;
+               }
 
                source = fwnode_graph_get_remote_endpoint(ep);
                if (!source) {
@@ -198,14 +197,15 @@ static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1)
                                "endpoint %pfw has no remote endpoint\n",
                                ep);
                        ret = -ENODEV;
-                       goto err_parse;
+                       break;
                }
 
                rk_asd = v4l2_async_nf_add_fwnode(ntf, source,
                                                  struct rkisp1_sensor_async);
                if (IS_ERR(rk_asd)) {
+                       fwnode_handle_put(source);
                        ret = PTR_ERR(rk_asd);
-                       goto err_parse;
+                       break;
                }
 
                rk_asd->index = index++;
@@ -216,27 +216,23 @@ static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1)
 
                dev_dbg(rkisp1->dev, "registered ep id %d with %d lanes\n",
                        vep.base.id, rk_asd->lanes);
+       }
 
-               next_id = vep.base.id + 1;
-
-               fwnode_handle_put(ep);
-
-               continue;
-err_parse:
+       if (ret) {
                fwnode_handle_put(ep);
-               fwnode_handle_put(source);
                v4l2_async_nf_cleanup(ntf);
                return ret;
        }
 
-       if (next_id == 0)
+       if (!index)
                dev_dbg(rkisp1->dev, "no remote subdevice found\n");
-       ntf->ops = &rkisp1_subdev_notifier_ops;
+
        ret = v4l2_async_nf_register(&rkisp1->v4l2_dev, ntf);
        if (ret) {
                v4l2_async_nf_cleanup(ntf);
                return ret;
        }
+
        return 0;
 }