public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls
@ 2023-08-25 22:13 Christophe JAILLET
  2023-08-28  7:34 ` Jacopo Mondi
  2023-08-28 10:59 ` Laurent Pinchart
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2023-08-25 22:13 UTC (permalink / raw)
  To: Jacopo Mondi, Kieran Bingham, Laurent Pinchart,
	Niklas Söderlund, Mauro Carvalho Chehab, Sakari Ailus
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	Mauro Carvalho Chehab, linux-media

This is odd to have a of_node_put() just after a for_each_child_of_node()
or a for_each_endpoint_of_node() loop. It should already be called
during the last iteration.

Remove these calls.

Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
/!\  This patch is speculative, review with case  /!\
---
 drivers/media/i2c/max9286.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 20e7c7cf5eeb..f27a69b1b727 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 
 		i2c_mux_mask |= BIT(id);
 	}
-	of_node_put(node);
 	of_node_put(i2c_mux);
 
 	/* Parse the endpoints */
@@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 		priv->source_mask |= BIT(ep.port);
 		priv->nsources++;
 	}
-	of_node_put(node);
 
 	of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width);
 	switch (priv->bus_width) {
-- 
2.34.1


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

* Re: [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls
  2023-08-25 22:13 [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls Christophe JAILLET
@ 2023-08-28  7:34 ` Jacopo Mondi
  2023-08-28 10:51   ` Kieran Bingham
  2023-08-28 10:59 ` Laurent Pinchart
  1 sibling, 1 reply; 4+ messages in thread
From: Jacopo Mondi @ 2023-08-28  7:34 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Jacopo Mondi, Kieran Bingham, Laurent Pinchart,
	Niklas Söderlund, Mauro Carvalho Chehab, Sakari Ailus,
	linux-kernel, kernel-janitors, Mauro Carvalho Chehab, linux-media

Hi Christophe

On Sat, Aug 26, 2023 at 12:13:40AM +0200, Christophe JAILLET wrote:
> This is odd to have a of_node_put() just after a for_each_child_of_node()
> or a for_each_endpoint_of_node() loop. It should already be called
> during the last iteration.

Let's unwrap the calls:

#define for_each_child_of_node(parent, child) \
     for (child = of_get_next_child(parent, NULL); child != NULL; \
          child = of_get_next_child(parent, child))

static struct device_node *__of_get_next_child(const struct device_node *node,
						struct device_node *prev)
{
	struct device_node *next;

	if (!node)
		return NULL;

	next = prev ? prev->sibling : node->child;
	of_node_get(next);
	of_node_put(prev);
	return next;
}

Let's express the C for loop semantic as a while to help following the
code:

        child = of_get_next_child(parent, NULL);
        while (child != NULL)
                child = of_get_next_child(parent, child);

I concur that the last loop iteration the call to
__of_get_next_child() will expand to

        next = NULL;
        of_node_get(NULL);
        of_node_put(prev)

So it seems to me it is not necessary to put the node after
for_each_child_of_node() ?

In facts none of the other usages of for_each_child_of_node() in the
kernel (the ones i checked at least) have a put() after the loop.

>
> Remove these calls.
>
> Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Thanks
  j

> ---
> /!\  This patch is speculative, review with case  /!\
> ---
>  drivers/media/i2c/max9286.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
> index 20e7c7cf5eeb..f27a69b1b727 100644
> --- a/drivers/media/i2c/max9286.c
> +++ b/drivers/media/i2c/max9286.c
> @@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
>
>  		i2c_mux_mask |= BIT(id);
>  	}
> -	of_node_put(node);
>  	of_node_put(i2c_mux);
>
>  	/* Parse the endpoints */
> @@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
>  		priv->source_mask |= BIT(ep.port);
>  		priv->nsources++;
>  	}
> -	of_node_put(node);
>
>  	of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width);
>  	switch (priv->bus_width) {
> --
> 2.34.1
>

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

* Re: [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls
  2023-08-28  7:34 ` Jacopo Mondi
@ 2023-08-28 10:51   ` Kieran Bingham
  0 siblings, 0 replies; 4+ messages in thread
From: Kieran Bingham @ 2023-08-28 10:51 UTC (permalink / raw)
  To: Christophe JAILLET, Jacopo Mondi
  Cc: Jacopo Mondi, Laurent Pinchart, Niklas Söderlund,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel,
	kernel-janitors, Mauro Carvalho Chehab, linux-media

Quoting Jacopo Mondi (2023-08-28 08:34:40)
> Hi Christophe
> 
> On Sat, Aug 26, 2023 at 12:13:40AM +0200, Christophe JAILLET wrote:
> > This is odd to have a of_node_put() just after a for_each_child_of_node()
> > or a for_each_endpoint_of_node() loop. It should already be called
> > during the last iteration.
> 
> Let's unwrap the calls:
> 
> #define for_each_child_of_node(parent, child) \
>      for (child = of_get_next_child(parent, NULL); child != NULL; \
>           child = of_get_next_child(parent, child))
> 
> static struct device_node *__of_get_next_child(const struct device_node *node,
>                                                 struct device_node *prev)
> {
>         struct device_node *next;
> 
>         if (!node)
>                 return NULL;
> 
>         next = prev ? prev->sibling : node->child;
>         of_node_get(next);
>         of_node_put(prev);
>         return next;
> }
> 
> Let's express the C for loop semantic as a while to help following the
> code:
> 
>         child = of_get_next_child(parent, NULL);
>         while (child != NULL)
>                 child = of_get_next_child(parent, child);
> 
> I concur that the last loop iteration the call to
> __of_get_next_child() will expand to
> 
>         next = NULL;
>         of_node_get(NULL);
>         of_node_put(prev)
> 
> So it seems to me it is not necessary to put the node after
> for_each_child_of_node() ?
> 
> In facts none of the other usages of for_each_child_of_node() in the
> kernel (the ones i checked at least) have a put() after the loop.

I agree. As long as the loops don't use any break statement - there
shouldn't be any _put() after the completion of the loop.

That would make a good cocci script - make sure these iterators do not
use 'break' internally - as that would then conflict!


Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

> 
> >
> > Remove these calls.
> >
> > Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver")
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> 
> Thanks
>   j
> 
> > ---
> > /!\  This patch is speculative, review with case  /!\
> > ---
> >  drivers/media/i2c/max9286.c | 2 --
> >  1 file changed, 2 deletions(-)
> >
> > diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
> > index 20e7c7cf5eeb..f27a69b1b727 100644
> > --- a/drivers/media/i2c/max9286.c
> > +++ b/drivers/media/i2c/max9286.c
> > @@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
> >
> >               i2c_mux_mask |= BIT(id);
> >       }
> > -     of_node_put(node);
> >       of_node_put(i2c_mux);
> >
> >       /* Parse the endpoints */
> > @@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
> >               priv->source_mask |= BIT(ep.port);
> >               priv->nsources++;
> >       }
> > -     of_node_put(node);
> >
> >       of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width);
> >       switch (priv->bus_width) {
> > --
> > 2.34.1
> >

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

* Re: [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls
  2023-08-25 22:13 [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls Christophe JAILLET
  2023-08-28  7:34 ` Jacopo Mondi
@ 2023-08-28 10:59 ` Laurent Pinchart
  1 sibling, 0 replies; 4+ messages in thread
From: Laurent Pinchart @ 2023-08-28 10:59 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Jacopo Mondi, Kieran Bingham, Niklas Söderlund,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel,
	kernel-janitors, Mauro Carvalho Chehab, linux-media

Hi Christophe,

Thank you for the patch.

On Sat, Aug 26, 2023 at 12:13:40AM +0200, Christophe JAILLET wrote:
> This is odd to have a of_node_put() just after a for_each_child_of_node()
> or a for_each_endpoint_of_node() loop. It should already be called
> during the last iteration.
> 
> Remove these calls.
> 
> Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

> ---
> /!\  This patch is speculative, review with case  /!\
> ---
>  drivers/media/i2c/max9286.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
> index 20e7c7cf5eeb..f27a69b1b727 100644
> --- a/drivers/media/i2c/max9286.c
> +++ b/drivers/media/i2c/max9286.c
> @@ -1450,7 +1450,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
>  
>  		i2c_mux_mask |= BIT(id);
>  	}
> -	of_node_put(node);
>  	of_node_put(i2c_mux);
>  
>  	/* Parse the endpoints */
> @@ -1514,7 +1513,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
>  		priv->source_mask |= BIT(ep.port);
>  		priv->nsources++;
>  	}
> -	of_node_put(node);
>  
>  	of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width);
>  	switch (priv->bus_width) {

-- 
Regards,

Laurent Pinchart

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

end of thread, other threads:[~2023-08-28 11:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25 22:13 [PATCH] media: i2c: max9286: Fix some redundant of_node_put() calls Christophe JAILLET
2023-08-28  7:34 ` Jacopo Mondi
2023-08-28 10:51   ` Kieran Bingham
2023-08-28 10:59 ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox