media: i2c: replacing of_node_put with __free(device_node)

Message ID 20240508054253.1568781-1-abdulrasaqolawani@gmail.com (mailing list archive)
State New
Delegated to: Sakari Ailus
Headers
Series media: i2c: replacing of_node_put with __free(device_node) |

Commit Message

Abdulrasaq Lawani May 8, 2024, 5:42 a.m. UTC
  Replaced instance of of_node_put with __free(device_node)
and removed goto statement to protect against any memory leaks
due to future changes in control flow.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Abdulrasaq Lawani <abdulrasaqolawani@gmail.com>
---
 drivers/media/i2c/ov5647.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
  

Comments

Julia Lawall May 8, 2024, 6:28 a.m. UTC | #1
On Wed, 8 May 2024, Abdulrasaq Lawani wrote:

> Replaced instance of of_node_put with __free(device_node)
> and removed goto statement to protect against any memory leaks
> due to future changes in control flow.

The log message is not very understandable.  "to protect..." goes with
__free, not with "removed goto statement".  I don't think "removed goto
statement" is needed at all.

julia


>
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: Abdulrasaq Lawani <abdulrasaqolawani@gmail.com>
> ---
>  drivers/media/i2c/ov5647.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index 7e1ecdf2485f..d593dba092e3 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -1360,23 +1360,19 @@ static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
>  	struct v4l2_fwnode_endpoint bus_cfg = {
>  		.bus_type = V4L2_MBUS_CSI2_DPHY,
>  	};
> -	struct device_node *ep;
> +	struct device_node *ep __free(device_node) = of_graph_get_endpoint_by_regs(np, 0, -1);
>  	int ret;
>
> -	ep = of_graph_get_endpoint_by_regs(np, 0, -1);
>  	if (!ep)
>  		return -EINVAL;
>
>  	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
>  	if (ret)
> -		goto out;
> +		return ret;
>
>  	sensor->clock_ncont = bus_cfg.bus.mipi_csi2.flags &
>  			      V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
>
> -out:
> -	of_node_put(ep);
> -
>  	return ret;
>  }
>
> --
> 2.34.1
>
>
  

Patch

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 7e1ecdf2485f..d593dba092e3 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -1360,23 +1360,19 @@  static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
 	struct v4l2_fwnode_endpoint bus_cfg = {
 		.bus_type = V4L2_MBUS_CSI2_DPHY,
 	};
-	struct device_node *ep;
+	struct device_node *ep __free(device_node) = of_graph_get_endpoint_by_regs(np, 0, -1);
 	int ret;
 
-	ep = of_graph_get_endpoint_by_regs(np, 0, -1);
 	if (!ep)
 		return -EINVAL;
 
 	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
 	if (ret)
-		goto out;
+		return ret;
 
 	sensor->clock_ncont = bus_cfg.bus.mipi_csi2.flags &
 			      V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
 
-out:
-	of_node_put(ep);
-
 	return ret;
 }