LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: i2c: replacing of_node_put with __free(device_node)
@ 2024-05-08  5:42 Abdulrasaq Lawani
  2024-05-08  6:28 ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Abdulrasaq Lawani @ 2024-05-08  5:42 UTC (permalink / raw
  To: akari.ailus, dave.stevenson, jacopo, mchehab, linux-media,
	linux-kernel, julia.lawall
  Cc: Abdulrasaq Lawani, skhan, javier.carrasco.cruz

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(-)

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: i2c: replacing of_node_put with __free(device_node)
  2024-05-08  5:42 Abdulrasaq Lawani
@ 2024-05-08  6:28 ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2024-05-08  6:28 UTC (permalink / raw
  To: Abdulrasaq Lawani
  Cc: akari.ailus, dave.stevenson, jacopo, mchehab, linux-media,
	linux-kernel, julia.lawall, skhan, javier.carrasco.cruz



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
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] media: i2c: replacing of_node_put with __free(device_node)
@ 2024-05-10 10:03 Abdulrasaq Lawani
  2024-06-11 15:18 ` Dave Stevenson
  0 siblings, 1 reply; 4+ messages in thread
From: Abdulrasaq Lawani @ 2024-05-10 10:03 UTC (permalink / raw
  To: sakari.ailus, dave.stevenson, jacopo, mchehab, julia.lawall
  Cc: Abdulrasaq Lawani, linux-media, linux-kernel, skhan,
	javier.carrasco.cruz

Replaced instance of of_node_put with __free(device_node)
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(-)

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: i2c: replacing of_node_put with __free(device_node)
  2024-05-10 10:03 [PATCH] media: i2c: replacing of_node_put with __free(device_node) Abdulrasaq Lawani
@ 2024-06-11 15:18 ` Dave Stevenson
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Stevenson @ 2024-06-11 15:18 UTC (permalink / raw
  To: Abdulrasaq Lawani
  Cc: sakari.ailus, jacopo, mchehab, julia.lawall, linux-media,
	linux-kernel, skhan, javier.carrasco.cruz

Hi

Thanks for the patch.

The subject should be "media: i2c: ov5647:" or just "media: ov5647" as
you're only touching the one driver.

On Fri, 10 May 2024 at 11:11, Abdulrasaq Lawani
<abdulrasaqolawani@gmail.com> wrote:
>
> Replaced instance of of_node_put with __free(device_node)
> 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(-)
>
> 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);

The media subsystem still requests a max line length of 80.
https://github.com/torvalds/linux/blob/master/Documentation/driver-api/media/maintainer-entry-profile.rst#coding-style-addendum
Break the line after the =

>         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;

This could be "return 0;" as you've already returned if it was non-zero.

I know very little of this new mechanism, but it looks reasonable, and
Sakari has given it a basic blessing in a previous patch set.
With the above 3 comments addressed:
Acked-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

>  }

>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-11 15:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-10 10:03 [PATCH] media: i2c: replacing of_node_put with __free(device_node) Abdulrasaq Lawani
2024-06-11 15:18 ` Dave Stevenson
  -- strict thread matches above, loose matches on Subject: below --
2024-05-08  5:42 Abdulrasaq Lawani
2024-05-08  6:28 ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).