Skip to contentSkip to conversation

media: i2c: st-mipid02: replace of_node_put() with __free

PATCH In review R Sundar 2 participants 4 messages Apr 29, 2024 – May 15, 2024

Subsystems (2)
lore
Share & tools
lore

R Sundar

author
#0 lore raw

PATCH v2 1/1 media: i2c: st-mipid02: replace of_node_put() with __free

Use the new cleanup magic to replace of_node_put() with __free(device_node) marking to auto release and to simplify the error paths.

---

Changes since v1 -

- Added missed out __free() marking in mipid02_parse_tx_ep().
- In mipid02_parse_tx_ep(), In error case, return value is always -EINVAL. so sending the -EINVAL instead of ret variable value.

Link to v1 - https://lore.kernel.org/all/[email protected]/#t

 drivers/media/i2c/st-mipid02.c | 37 +++++++++-------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)
drivers/media/i2c/st-mipid02.c +9 -28
index f250640729ca..bd3cf94f8534 100644
@@ -715,31 +715,28 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
 	struct i2c_client *client = bridge->i2c_client;
 	struct v4l2_async_connection *asd;
-	struct device_node *ep_node;
 	int ret;
 
 	/* parse rx (endpoint 0) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						0, 0);
+	struct device_node *ep_node __free(device_node) =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 0, 0);
 	if (!ep_node) {
 		dev_err(&client->dev, "unable to find port0 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
 	if (ret) {
 		dev_err(&client->dev, "Could not parse v4l2 endpoint %d\n",
 			ret);
-		goto error_of_node_put;
+		return ret;
 	}
 
 	/* do some sanity checks */
 	if (ep.bus.mipi_csi2.num_data_lanes > 2) {
 		dev_err(&client->dev, "max supported data lanes is 2 / got %d",
 			ep.bus.mipi_csi2.num_data_lanes);
-		ret = -EINVAL;
-		goto error_of_node_put;
+		return -EINVAL;
 	}
 
 	/* register it for later use */
@@ -750,7 +747,6 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 	asd = v4l2_async_nf_add_fwnode_remote(&bridge->notifier,
 					      of_fwnode_handle(ep_node),
 					      struct v4l2_async_connection);
-	of_node_put(ep_node);
 
 	if (IS_ERR(asd)) {
 		dev_err(&client->dev, "fail to register asd to notifier %ld",
@@ -764,46 +760,31 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 		v4l2_async_nf_cleanup(&bridge->notifier);
 
 	return ret;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return ret;
 }
 
 static int mipid02_parse_tx_ep(struct mipid02_dev *bridge)
 {
 	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_PARALLEL };
 	struct i2c_client *client = bridge->i2c_client;
-	struct device_node *ep_node;
 	int ret;
 
 	/* parse tx (endpoint 2) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						2, 0);
+	struct device_node *ep_node __free(device_node) =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 2, 0);
 	if (!ep_node) {
 		dev_err(&client->dev, "unable to find port1 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
 	if (ret) {
 		dev_err(&client->dev, "Could not parse v4l2 endpoint\n");
-		goto error_of_node_put;
+		return -EINVAL;
 	}
 
-	of_node_put(ep_node);
 	bridge->tx = ep;
 
 	return 0;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return -EINVAL;
 }
 
 static int mipid02_probe(struct i2c_client *client)
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi,

I took sometime to reflect on this. Currently I favor drivers consistency. Merging this patch as is would introduce some differences between the vgxy61 and other drivers that follow the 'of_node_put' flow, which I think is not an improvement.

Now, this patch is certainly good. Would it be possible to extend it to all other drivers using the 'of_node_put' ?

That would the consistency issue while improving code quality at the same time.

Thank you.

Quoted 119 lines · R Sundar

Use the new cleanup magic to replace of_node_put() with __free(device_node) marking to auto release and to simplify the error paths.

---

Changes since v1 -

- Added missed out __free() marking in mipid02_parse_tx_ep().
- In mipid02_parse_tx_ep(), In error case, return value is always -EINVAL. so sending the -EINVAL instead of ret variable value.

Link to v1 - https://lore.kernel.org/all/[email protected]/#t

 drivers/media/i2c/st-mipid02.c | 37 +++++++++-------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)
drivers/media/i2c/st-mipid02.c +9 -28
index f250640729ca..bd3cf94f8534 100644
@@ -715,31 +715,28 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
 	struct i2c_client *client = bridge->i2c_client;
 	struct v4l2_async_connection *asd;
-	struct device_node *ep_node;
 	int ret;
 
 	/* parse rx (endpoint 0) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						0, 0);
+	struct device_node *ep_node __free(device_node) =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 0, 0);
 	if (!ep_node) {
 		dev_err(&client->dev, "unable to find port0 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
 	if (ret) {
 		dev_err(&client->dev, "Could not parse v4l2 endpoint %d\n",
 			ret);
-		goto error_of_node_put;
+		return ret;
 	}
 
 	/* do some sanity checks */
 	if (ep.bus.mipi_csi2.num_data_lanes > 2) {
 		dev_err(&client->dev, "max supported data lanes is 2 / got %d",
 			ep.bus.mipi_csi2.num_data_lanes);
-		ret = -EINVAL;
-		goto error_of_node_put;
+		return -EINVAL;
 	}
 
 	/* register it for later use */
@@ -750,7 +747,6 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 	asd = v4l2_async_nf_add_fwnode_remote(&bridge->notifier,
 					      of_fwnode_handle(ep_node),
 					      struct v4l2_async_connection);
-	of_node_put(ep_node);
 
 	if (IS_ERR(asd)) {
 		dev_err(&client->dev, "fail to register asd to notifier %ld",
@@ -764,46 +760,31 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
 		v4l2_async_nf_cleanup(&bridge->notifier);
 
 	return ret;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return ret;
 }
 
 static int mipid02_parse_tx_ep(struct mipid02_dev *bridge)
 {
 	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_PARALLEL };
 	struct i2c_client *client = bridge->i2c_client;
-	struct device_node *ep_node;
 	int ret;
 
 	/* parse tx (endpoint 2) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						2, 0);
+	struct device_node *ep_node __free(device_node) =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 2, 0);
 	if (!ep_node) {
 		dev_err(&client->dev, "unable to find port1 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
 	}
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
 	if (ret) {
 		dev_err(&client->dev, "Could not parse v4l2 endpoint\n");
-		goto error_of_node_put;
+		return -EINVAL;
 	}
 
-	of_node_put(ep_node);
 	bridge->tx = ep;
 
 	return 0;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return -EINVAL;
 }
 
 static int mipid02_probe(struct i2c_client *client)
Signature · 3 lines
Regards,

Benjamin
author
#2 lore raw

Hi,

Thanks for the comments.

Quoted 9 lines · Benjamin Mugnier

Hi,

I took sometime to reflect on this. Currently I favor drivers consistency.

Merging this patch as is would introduce some differences between the vgxy61 and other drivers that follow the 'of_node_put' flow, which I think is not an improvement.

I checked st-vgxy61.c file, I didn't find of_node_put().
Any file apart from this, you want to see those changes? If yes let me know, please. Meanwhile I am also looking into it.

This patch mainly reduce the goto error statements and increases readability of the code.

Quoted 3 lines

Now, this patch is certainly good. Would it be possible to extend it to all other drivers using the 'of_node_put' ?

yes, people are working on it to replace of_node_put() in many places. soon many patches can be expected to come in , for replacing of_node_put with auto cleanup module. I am also adding these changes to few other files also.

Thanks,

Quoted 126 lines

That would the consistency issue while improving code quality at the same time.

Thank you.

Quoted 1 line
Quoted 119 lines · R Sundar

Use the new cleanup magic to replace of_node_put() with __free(device_node) marking to auto release and to simplify the error paths.

---

Changes since v1 -

- Added missed out __free() marking in mipid02_parse_tx_ep().
- In mipid02_parse_tx_ep(), In error case, return value is always -EINVAL. so sending the -EINVAL instead of ret variable value.

Link to v1 - https://lore.kernel.org/all/[email protected]/#t

  drivers/media/i2c/st-mipid02.c | 37 +++++++++-------------------------
  1 file changed, 9 insertions(+), 28 deletions(-)
drivers/media/i2c/st-mipid02.c +9 -28
index f250640729ca..bd3cf94f8534 100644
@@ -715,31 +715,28 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
  	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
  	struct i2c_client *client = bridge->i2c_client;
  	struct v4l2_async_connection *asd;
-	struct device_node *ep_node;
  	int ret;
 
  	/* parse rx (endpoint 0) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						0, 0);
+	struct device_node *ep_node __free(device_node) =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 0, 0);
  	if (!ep_node) {
  		dev_err(&client->dev, "unable to find port0 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
  	}
 
  	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
  	if (ret) {
  		dev_err(&client->dev, "Could not parse v4l2 endpoint %d\n",
  			ret);
-		goto error_of_node_put;
+		return ret;
  	}
 
  	/* do some sanity checks */
  	if (ep.bus.mipi_csi2.num_data_lanes > 2) {
  		dev_err(&client->dev, "max supported data lanes is 2 / got %d",
  			ep.bus.mipi_csi2.num_data_lanes);
-		ret = -EINVAL;
-		goto error_of_node_put;
+		return -EINVAL;
  	}
 
  	/* register it for later use */
@@ -750,7 +747,6 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
  	asd = v4l2_async_nf_add_fwnode_remote(&bridge->notifier,
  					      of_fwnode_handle(ep_node),
  					      struct v4l2_async_connection);
-	of_node_put(ep_node);
 
  	if (IS_ERR(asd)) {
  		dev_err(&client->dev, "fail to register asd to notifier %ld",
@@ -764,46 +760,31 @@ static int mipid02_parse_rx_ep(struct mipid02_dev *bridge)
  		v4l2_async_nf_cleanup(&bridge->notifier);
 
  	return ret;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return ret;
  }
 
  static int mipid02_parse_tx_ep(struct mipid02_dev *bridge)
  {
  	struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_PARALLEL };
  	struct i2c_client *client = bridge->i2c_client;
-	struct device_node *ep_node;
  	int ret;
 
  	/* parse tx (endpoint 2) */
-	ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node,
-						2, 0);
+	struct device_node *ep_node __free(device_node) =
+		of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 2, 0);
  	if (!ep_node) {
  		dev_err(&client->dev, "unable to find port1 ep");
-		ret = -EINVAL;
-		goto error;
+		return -EINVAL;
  	}
 
  	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
  	if (ret) {
  		dev_err(&client->dev, "Could not parse v4l2 endpoint\n");
-		goto error_of_node_put;
+		return -EINVAL;
  	}
 
-	of_node_put(ep_node);
  	bridge->tx = ep;
 
  	return 0;
-
-error_of_node_put:
-	of_node_put(ep_node);
-error:
-
-	return -EINVAL;
  }
 
  static int mipid02_probe(struct i2c_client *client)
maintainer
#3 lore raw

Hi,

Quoted 11 lines · R Sundar

Hi,

Thanks for the comments.

Quoted 4 lines · Benjamin Mugnier

Hi,

I took sometime to reflect on this. Currently I favor drivers consistency.

Quoted 6 lines
Quoted 4 lines

Merging this patch as is would introduce some differences between the vgxy61 and other drivers that follow the 'of_node_put' flow, which I think is not an improvement.

I checked st-vgxy61.c file, I didn't find of_node_put().

Apologize, I meant st-mipid02.

Quoted 7 lines

Any file apart from this,  you want to see those changes? If yes let me know, please.
Meanwhile I am also looking into it.

This patch mainly reduce the goto error statements and increases readability of the code.

Quoted 7 lines
Quoted 3 lines

Now, this patch is certainly good. Would it be possible to extend it to all other drivers using the 'of_node_put' ?

yes, people are working on it to replace of_node_put() in many places. soon many patches can be expected to come in , for replacing of_node_put with auto cleanup module.
I am also adding these changes to few other files also.

Good, I'd rather see a series with all these files then to ease the review. But I only maintain the st-mipid02 so other people opinion may differ.

Quoted 132 lines

Thanks,

Quoted 129 lines
Quoted 1 line

That would the consistency issue while improving code quality at the

same time.

Thank you.
 >

Quoted 122 lines · R Sundar

Use the new cleanup magic to replace of_node_put() with __free(device_node) marking to auto release and to simplify the error paths.

---

Changes since v1 -

- Added missed out __free() marking in mipid02_parse_tx_ep().
- In mipid02_parse_tx_ep(), In error case, return value is always -EINVAL.  so
sending the -EINVAL instead of ret variable value.

Link to v1 -
https://lore.kernel.org/all/[email protected]/#t

  drivers/media/i2c/st-mipid02.c | 37 +++++++++-------------------------

  1 file changed, 9 insertions(+), 28 deletions(-)
drivers/media/i2c/st-mipid02.c +0 -0
index f250640729ca..bd3cf94f8534 100644
@@ -715,31 +715,28 @@ static int mipid02_parse_rx_ep(struct
 mipid02_dev *bridge)

      struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_CSI2_DPHY };
      struct i2c_client *client = bridge->i2c_client; struct v4l2_async_connection *asd;
-    struct device_node *ep_node;
      int ret;
        /* parse rx (endpoint 0) */
-    ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, -                        0, 0);
+    struct device_node *ep_node __free(device_node) =
+ of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 0, 0); if (!ep_node) {
          dev_err(&client->dev, "unable to find port0 ep"); -        ret = -EINVAL;
-        goto error;
+        return -EINVAL;
      }
        ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
      if (ret) {
          dev_err(&client->dev, "Could not parse v4l2 endpoint %d\n", ret);
-        goto error_of_node_put;
+        return ret;
      }
        /* do some sanity checks */
      if (ep.bus.mipi_csi2.num_data_lanes > 2) { dev_err(&client->dev, "max supported data lanes is 2 / got %d",
              ep.bus.mipi_csi2.num_data_lanes);
-        ret = -EINVAL;
-        goto error_of_node_put;
+        return -EINVAL;
      }
        /* register it for later use */

drivers/media/i2c/st-mipid02.c +0 -7
@@ -750,7 +747,6 @@ static int mipid02_parse_rx_ep(struct mipid02_dev
 *bridge)
       asd = v4l2_async_nf_add_fwnode_remote(&bridge->notifier,
                             of_fwnode_handle(ep_node),
                             struct v4l2_async_connection);
-    of_node_put(ep_node);
         if (IS_ERR(asd)) {
           dev_err(&client->dev, "fail to register asd to notifier %ld",
@@ -764,46 +760,31 @@ static int mipid02_parse_rx_ep(struct
 mipid02_dev *bridge)
           v4l2_async_nf_cleanup(&bridge->notifier);
         return ret;
-
-error_of_node_put:
-    of_node_put(ep_node);
-error:
-
-    return ret;
   }
     static int mipid02_parse_tx_ep(struct mipid02_dev *bridge)
   {

      struct v4l2_fwnode_endpoint ep = { .bus_type = V4L2_MBUS_PARALLEL };
      struct i2c_client *client = bridge->i2c_client;
-    struct device_node *ep_node;
      int ret;
        /* parse tx (endpoint 2) */
-    ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, -                        2, 0);
+    struct device_node *ep_node __free(device_node) =
+ of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, 2, 0); if (!ep_node) {
          dev_err(&client->dev, "unable to find port1 ep"); -        ret = -EINVAL;
-        goto error;
+        return -EINVAL;
      }
        ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep_node), &ep);
      if (ret) {
          dev_err(&client->dev, "Could not parse v4l2 endpoint\n"); -        goto error_of_node_put;
+        return -EINVAL;
      }
  -    of_node_put(ep_node);
      bridge->tx = ep;
        return 0;

drivers/media/i2c/st-mipid02.c +0 -6
-
-error_of_node_put:
-    of_node_put(ep_node);
-error:
-
-    return -EINVAL;

  }
    static int mipid02_probe(struct i2c_client *client)

Signature · 3 lines
Regards,

Benjamin