Skip to contentSkip to conversation

media: imx: imx7-media-csi: Fix error handling in imx7_csi_async_register()

PATCH Superseded Frieder Schrempf 2 participants 2 messages Feb 14, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: imx: imx7-media-csi: Fix error handling in imx7_csi_async_register()

From: Frieder Schrempf <[email protected]>

If fwnode_graph_get_endpoint_by_id() fails and returns NULL, there is no point in going on. Print an error message a abort instead.

Also we don't need to check for an existing asd. Any failure of v4l2_async_nf_add_fwnode_remote() should abort the probe.

---
 drivers/media/platform/nxp/imx7-media-csi.c | 22 +++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/platform/nxp/imx7-media-csi.c +12 -10
index 886374d3a6ff..a7db310624e2 100644
@@ -2191,18 +2191,20 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 
 	ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(csi->dev), 0, 0,
 					     FWNODE_GRAPH_ENDPOINT_NEXT);
-	if (ep) {
-		asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
-						      struct v4l2_async_subdev);
+	if (!ep) {
+		dev_err(csi->dev, "Failed to get remote endpoint\n");
+		return -ENOTCONN;
+	}
 
-		fwnode_handle_put(ep);
+	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
+					      struct v4l2_async_subdev);
 
-		if (IS_ERR(asd)) {
-			ret = PTR_ERR(asd);
-			/* OK if asd already exists */
-			if (ret != -EEXIST)
-				return ret;
-		}
+	fwnode_handle_put(ep);
+
+	if (IS_ERR(asd)) {
+		ret = PTR_ERR(asd);
+		dev_err(csi->dev, "Failed to add remote subdev to notifier: %d\n", ret);
+		return ret;
 	}
 
 	csi->notifier.ops = &imx7_csi_notify_ops;
Signature · 7 lines
2.39.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw

Hi Frieder,

Thank you for the patch.

Quoted 4 lines · Frieder Schrempf

From: Frieder Schrempf <[email protected]>

If fwnode_graph_get_endpoint_by_id() fails and returns NULL, there is no point in going on. Print an error message a abort instead.

s/a abort/and abort/

Explaining why as a reference to future readers would be nice:

The CSI requires a connected source subdev to operate. If fwnode_graph_get_endpoint_by_id() fails and returns NULL, there is no point in going on. Print an error message and abort instead.

Quoted 14 lines

Also we don't need to check for an existing asd. Any failure of v4l2_async_nf_add_fwnode_remote() should abort the probe.

---
 drivers/media/platform/nxp/imx7-media-csi.c | 22 +++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/platform/nxp/imx7-media-csi.c +0 -0
index 886374d3a6ff..a7db310624e2 100644

drivers/media/platform/nxp/imx7-media-csi.c static int imx7_csi_async_register(struct imx7_csi *csi) · line 2195

Quoted 8 lines
drivers/media/platform/nxp/imx7-media-csi.c +2 -3
@@ -2191,18 +2191,20 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 
 	ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(csi->dev), 0, 0,
 					     FWNODE_GRAPH_ENDPOINT_NEXT);
-	if (ep) {
-		asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
-						      struct v4l2_async_subdev);
+	if (!ep) {
+		dev_err(csi->dev, "Failed to get remote endpoint\n");

Let's use dev_err_probe() as this is called from the probe function:

		dev_err_probe(csi->dev, -ENOTCONN,
			      "Failed to get remote endpoint\n");
Quoted 8 lines
drivers/media/platform/nxp/imx7-media-csi.c +4 -2
+		return -ENOTCONN;
+	}
 
-		fwnode_handle_put(ep);
+	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
+					      struct v4l2_async_subdev);
 
-		if (IS_ERR(asd)) {

drivers/media/platform/nxp/imx7-media-csi.c static int imx7_csi_async_register(struct imx7_csi *csi) · line 2206

Quoted 10 lines
drivers/media/platform/nxp/imx7-media-csi.c +5 -5
-			ret = PTR_ERR(asd);
-			/* OK if asd already exists */
-			if (ret != -EEXIST)
-				return ret;
-		}
+	fwnode_handle_put(ep);
+
+	if (IS_ERR(asd)) {
+		ret = PTR_ERR(asd);
+		dev_err(csi->dev, "Failed to add remote subdev to notifier: %d\n", ret);

Same here:

		dev_err_probe(csi->dev, ret,
			      "Failed to add remote subdev to notifier\n");
Quoted 4 lines
drivers/media/platform/nxp/imx7-media-csi.c +1 -0
+		return ret;
 	}
 
 	csi->notifier.ops = &imx7_csi_notify_ops;
Signature · 3 lines
Regards,

Laurent Pinchart