devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sound/soc/fsl/fsl_dma.c: add missing of_node_put
@ 2011-08-20  7:23 Julia Lawall
  2011-08-22 10:18 ` Liam Girdwood
  2011-08-22 14:03 ` Timur Tabi
  0 siblings, 2 replies; 4+ messages in thread
From: Julia Lawall @ 2011-08-20  7:23 UTC (permalink / raw)
  To: Timur Tabi
  Cc: alsa-devel, Takashi Iwai, devicetree-discuss, Mark Brown,
	kernel-janitors, linux-kernel, Grant Likely, linuxppc-dev,
	Liam Girdwood

From: Julia Lawall <julia@diku.dk>

of_parse_phandle increments the reference count of np, so this should be
decremented before trying the next possibility.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e,e1,e2;
@@

*e = of_parse_phandle(...)
... when != of_node_put(e)
    when != true e == NULL
    when != e2 = e
e = e1
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 sound/soc/fsl/fsl_dma.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 0efc04a..b33271b 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -880,10 +880,12 @@ static struct device_node *find_ssi_node(struct device_node *dma_channel_np)
 		np = of_parse_phandle(ssi_np, "fsl,playback-dma", 0);
 		if (np == dma_channel_np)
 			return ssi_np;
+		of_node_put(np);
 
 		np = of_parse_phandle(ssi_np, "fsl,capture-dma", 0);
 		if (np == dma_channel_np)
 			return ssi_np;
+		of_node_put(np);
 	}
 
 	return NULL;

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

* Re: [PATCH] sound/soc/fsl/fsl_dma.c: add missing of_node_put
  2011-08-20  7:23 [PATCH] sound/soc/fsl/fsl_dma.c: add missing of_node_put Julia Lawall
@ 2011-08-22 10:18 ` Liam Girdwood
  2011-08-22 14:03 ` Timur Tabi
  1 sibling, 0 replies; 4+ messages in thread
From: Liam Girdwood @ 2011-08-22 10:18 UTC (permalink / raw)
  To: Julia Lawall
  Cc: alsa-devel@alsa-project.org, Takashi Iwai,
	devicetree-discuss@lists.ozlabs.org, Mark Brown,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
	Grant Likely, linuxppc-dev@lists.ozlabs.org, Timur Tabi

On 20/08/11 08:23, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> of_parse_phandle increments the reference count of np, so this should be
> decremented before trying the next possibility.
> 
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression e,e1,e2;
> @@
> 
> *e = of_parse_phandle(...)
> ... when != of_node_put(e)
>     when != true e == NULL
>     when != e2 = e
> e = e1
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> 
> ---
>  sound/soc/fsl/fsl_dma.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
> index 0efc04a..b33271b 100644
> --- a/sound/soc/fsl/fsl_dma.c
> +++ b/sound/soc/fsl/fsl_dma.c
> @@ -880,10 +880,12 @@ static struct device_node *find_ssi_node(struct device_node *dma_channel_np)
>  		np = of_parse_phandle(ssi_np, "fsl,playback-dma", 0);
>  		if (np == dma_channel_np)
>  			return ssi_np;
> +		of_node_put(np);
>  
>  		np = of_parse_phandle(ssi_np, "fsl,capture-dma", 0);
>  		if (np == dma_channel_np)
>  			return ssi_np;
> +		of_node_put(np);
>  	}
>  
>  	return NULL;
> 

Acked-by: Liam Girdwood <lrg@ti.com>

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

* Re: [PATCH] sound/soc/fsl/fsl_dma.c: add missing of_node_put
  2011-08-20  7:23 [PATCH] sound/soc/fsl/fsl_dma.c: add missing of_node_put Julia Lawall
  2011-08-22 10:18 ` Liam Girdwood
@ 2011-08-22 14:03 ` Timur Tabi
       [not found]   ` <4E5261A5.5050608-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Timur Tabi @ 2011-08-22 14:03 UTC (permalink / raw)
  To: Julia Lawall
  Cc: alsa-devel, Takashi Iwai, devicetree-discuss, Mark Brown,
	kernel-janitors, linux-kernel, Grant Likely, linuxppc-dev,
	Liam Girdwood

Julia Lawall wrote:
> diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
> index 0efc04a..b33271b 100644
> --- a/sound/soc/fsl/fsl_dma.c
> +++ b/sound/soc/fsl/fsl_dma.c
> @@ -880,10 +880,12 @@ static struct device_node *find_ssi_node(struct device_node *dma_channel_np)
>  		np = of_parse_phandle(ssi_np, "fsl,playback-dma", 0);
>  		if (np == dma_channel_np)
>  			return ssi_np;
> +		of_node_put(np);
>  
>  		np = of_parse_phandle(ssi_np, "fsl,capture-dma", 0);
>  		if (np == dma_channel_np)
>  			return ssi_np;
> +		of_node_put(np);
>  	}

Thanks for catching the problem, Julia, but the fix is not quite correct.  My
code assumes that of_parse_phandle() doesn't claim the node, but it doesn't
actually use the node pointer, either.  All I care about is whether 'np' is
equal to dma_channel_np.  I'm not going to use 'np'.  So I think the real fix is
this:

@@ -880,10 +880,12 @@ static struct device_node *find_ssi_node(struct
device_node *dma_channel_np)
 		np = of_parse_phandle(ssi_np, "fsl,playback-dma", 0);
+		of_node_put(np);
 		if (np == dma_channel_np)
 			return ssi_np;

 		np = of_parse_phandle(ssi_np, "fsl,capture-dma", 0);
+		of_node_put(np);
 		if (np == dma_channel_np)
 			return ssi_np;
 	}

 	return NULL;

-- 
Timur Tabi
Linux kernel developer at Freescale

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

* Re: [PATCH] sound/soc/fsl/fsl_dma.c: add missing of_node_put
       [not found]   ` <4E5261A5.5050608-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2011-08-22 14:06     ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2011-08-22 14:06 UTC (permalink / raw)
  To: Timur Tabi
  Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw, Takashi Iwai,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Mark Brown,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Jaroslav Kysela,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ, Liam Girdwood

On Mon, 22 Aug 2011, Timur Tabi wrote:

> Julia Lawall wrote:
> > diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
> > index 0efc04a..b33271b 100644
> > --- a/sound/soc/fsl/fsl_dma.c
> > +++ b/sound/soc/fsl/fsl_dma.c
> > @@ -880,10 +880,12 @@ static struct device_node *find_ssi_node(struct device_node *dma_channel_np)
> >  		np = of_parse_phandle(ssi_np, "fsl,playback-dma", 0);
> >  		if (np == dma_channel_np)
> >  			return ssi_np;
> > +		of_node_put(np);
> >  
> >  		np = of_parse_phandle(ssi_np, "fsl,capture-dma", 0);
> >  		if (np == dma_channel_np)
> >  			return ssi_np;
> > +		of_node_put(np);
> >  	}
> 
> Thanks for catching the problem, Julia, but the fix is not quite correct.  My
> code assumes that of_parse_phandle() doesn't claim the node, but it doesn't
> actually use the node pointer, either.  All I care about is whether 'np' is
> equal to dma_channel_np.  I'm not going to use 'np'.  So I think the real fix is
> this:
> 
> @@ -880,10 +880,12 @@ static struct device_node *find_ssi_node(struct
> device_node *dma_channel_np)
>  		np = of_parse_phandle(ssi_np, "fsl,playback-dma", 0);
> +		of_node_put(np);
>  		if (np == dma_channel_np)
>  			return ssi_np;
> 
>  		np = of_parse_phandle(ssi_np, "fsl,capture-dma", 0);
> +		of_node_put(np);
>  		if (np == dma_channel_np)
>  			return ssi_np;
>  	}
> 
>  	return NULL;

OK, that looks reasonable.

julia

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

end of thread, other threads:[~2011-08-22 14:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-20  7:23 [PATCH] sound/soc/fsl/fsl_dma.c: add missing of_node_put Julia Lawall
2011-08-22 10:18 ` Liam Girdwood
2011-08-22 14:03 ` Timur Tabi
     [not found]   ` <4E5261A5.5050608-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2011-08-22 14:06     ` 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 NNTP newsgroup(s).