mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed
@ 2011-10-18  3:45 Julia Lawall
  2011-10-18 13:01 ` Dong Aisheng-B29396
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2011-10-18  3:45 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: kernel-janitors, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Dong Aisheng, Wolfram Sang, alsa-devel, linux-kernel

From: Julia Lawall <julia@diku.dk>

Add a new variable for storing resources accessed subsequent to the one
accessed using request_mem_region, so the one accessed using
request_mem_region can be released if needed.

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

// <smpl>
@r@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@

if (E == NULL)
{
  ... when != if (E == NULL || ...) S1 else S2
      when != E = E1
*E->f
  ... when any
  return ...;
}
else S3
// </smpl>

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

---
 sound/soc/mxs/mxs-saif.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index 401944c..e12ff78 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -617,7 +617,7 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
 
 static int mxs_saif_probe(struct platform_device *pdev)
 {
-	struct resource *res;
+	struct resource *res, *res1;
 	struct mxs_saif *saif;
 	struct mxs_saif_platform_data *pdata;
 	int ret = 0;
@@ -676,14 +676,14 @@ static int mxs_saif_probe(struct platform_device *pdev)
 		goto failed_ioremap;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-	if (!res) {
+	res1 = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+	if (!res1) {
 		ret = -ENODEV;
 		dev_err(&pdev->dev, "failed to get dma resource: %d\n",
 			ret);
 		goto failed_ioremap;
 	}
-	saif->dma_param.chan_num = res->start;
+	saif->dma_param.chan_num = res1->start;
 
 	saif->irq = platform_get_irq(pdev, 0);
 	if (saif->irq < 0) {


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

* RE: [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed
  2011-10-18  3:45 [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed Julia Lawall
@ 2011-10-18 13:01 ` Dong Aisheng-B29396
  2011-10-18 13:06   ` Julia Lawall
  2011-10-18 13:18   ` Julia Lawall
  0 siblings, 2 replies; 7+ messages in thread
From: Dong Aisheng-B29396 @ 2011-10-18 13:01 UTC (permalink / raw)
  To: Julia Lawall, Liam Girdwood
  Cc: kernel-janitors, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Wolfram Sang, alsa-devel, linux-kernel

> -----Original Message-----
> From: Julia Lawall [mailto:julia@diku.dk]
> Sent: Tuesday, October 18, 2011 11:46 AM
> To: Liam Girdwood
> Cc: kernel-janitors@vger.kernel.org; Mark Brown; Jaroslav Kysela; Takashi
> Iwai; Dong Aisheng-B29396; Wolfram Sang; alsa-devel@alsa-project.org;
> linux-kernel@vger.kernel.org
> Subject: [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource
> so it can be freed
> 
> From: Julia Lawall <julia@diku.dk>
> 
> Add a new variable for storing resources accessed subsequent to the one
> accessed using request_mem_region, so the one accessed using
> request_mem_region can be released if needed.
> 
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @r@
> expression E, E1;
> identifier f;
> statement S1,S2,S3;
> @@
> 
> if (E == NULL)
> {
>   ... when != if (E == NULL || ...) S1 else S2
>       when != E = E1
> *E->f
>   ... when any
>   return ...;
> }
> else S3
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> 
> ---
>  sound/soc/mxs/mxs-saif.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index
> 401944c..e12ff78 100644
> --- a/sound/soc/mxs/mxs-saif.c
> +++ b/sound/soc/mxs/mxs-saif.c
> @@ -617,7 +617,7 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
> 
>  static int mxs_saif_probe(struct platform_device *pdev)  {
> -	struct resource *res;
> +	struct resource *res, *res1;
How about naming iores and dmares?

>  	struct mxs_saif *saif;
>  	struct mxs_saif_platform_data *pdata;
>  	int ret = 0;
> @@ -676,14 +676,14 @@ static int mxs_saif_probe(struct platform_device
> *pdev)
>  		goto failed_ioremap;
>  	}
> 
> -	res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
> -	if (!res) {
> +	res1 = platform_get_resource(pdev, IORESOURCE_DMA, 0);
> +	if (!res1) {
>  		ret = -ENODEV;
>  		dev_err(&pdev->dev, "failed to get dma resource: %d\n",
>  			ret);
>  		goto failed_ioremap;
>  	}
> -	saif->dma_param.chan_num = res->start;
> +	saif->dma_param.chan_num = res1->start;
> 
>  	saif->irq = platform_get_irq(pdev, 0);
>  	if (saif->irq < 0) {
> 

Regards
Dong Aisheng


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

* RE: [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed
  2011-10-18 13:01 ` Dong Aisheng-B29396
@ 2011-10-18 13:06   ` Julia Lawall
  2011-10-18 13:18   ` Julia Lawall
  1 sibling, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2011-10-18 13:06 UTC (permalink / raw)
  To: Dong Aisheng-B29396
  Cc: Liam Girdwood, kernel-janitors, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Wolfram Sang, alsa-devel, linux-kernel

On Tue, 18 Oct 2011, Dong Aisheng-B29396 wrote:

> > -----Original Message-----
> > From: Julia Lawall [mailto:julia@diku.dk]
> > Sent: Tuesday, October 18, 2011 11:46 AM
> > To: Liam Girdwood
> > Cc: kernel-janitors@vger.kernel.org; Mark Brown; Jaroslav Kysela; Takashi
> > Iwai; Dong Aisheng-B29396; Wolfram Sang; alsa-devel@alsa-project.org;
> > linux-kernel@vger.kernel.org
> > Subject: [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource
> > so it can be freed
> > 
> > From: Julia Lawall <julia@diku.dk>
> > 
> > Add a new variable for storing resources accessed subsequent to the one
> > accessed using request_mem_region, so the one accessed using
> > request_mem_region can be released if needed.
> > 
> > The semantic match that finds this problem is as follows:
> > (http://coccinelle.lip6.fr/)
> > 
> > // <smpl>
> > @r@
> > expression E, E1;
> > identifier f;
> > statement S1,S2,S3;
> > @@
> > 
> > if (E == NULL)
> > {
> >   ... when != if (E == NULL || ...) S1 else S2
> >       when != E = E1
> > *E->f
> >   ... when any
> >   return ...;
> > }
> > else S3
> > // </smpl>
> > 
> > Signed-off-by: Julia Lawall <julia@diku.dk>
> > 
> > ---
> >  sound/soc/mxs/mxs-saif.c |    8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index
> > 401944c..e12ff78 100644
> > --- a/sound/soc/mxs/mxs-saif.c
> > +++ b/sound/soc/mxs/mxs-saif.c
> > @@ -617,7 +617,7 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
> > 
> >  static int mxs_saif_probe(struct platform_device *pdev)  {
> > -	struct resource *res;
> > +	struct resource *res, *res1;
> How about naming iores and dmares?

Sure. I will change that.

thanks,
julia

> 
> >  	struct mxs_saif *saif;
> >  	struct mxs_saif_platform_data *pdata;
> >  	int ret = 0;
> > @@ -676,14 +676,14 @@ static int mxs_saif_probe(struct platform_device
> > *pdev)
> >  		goto failed_ioremap;
> >  	}
> > 
> > -	res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
> > -	if (!res) {
> > +	res1 = platform_get_resource(pdev, IORESOURCE_DMA, 0);
> > +	if (!res1) {
> >  		ret = -ENODEV;
> >  		dev_err(&pdev->dev, "failed to get dma resource: %d\n",
> >  			ret);
> >  		goto failed_ioremap;
> >  	}
> > -	saif->dma_param.chan_num = res->start;
> > +	saif->dma_param.chan_num = res1->start;
> > 
> >  	saif->irq = platform_get_irq(pdev, 0);
> >  	if (saif->irq < 0) {
> > 
> 
> Regards
> Dong Aisheng
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* RE: [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed
  2011-10-18 13:01 ` Dong Aisheng-B29396
  2011-10-18 13:06   ` Julia Lawall
@ 2011-10-18 13:18   ` Julia Lawall
  2011-10-18 13:26     ` [alsa-devel] " Mark Brown
  2011-10-18 14:10     ` Julia Lawall
  1 sibling, 2 replies; 7+ messages in thread
From: Julia Lawall @ 2011-10-18 13:18 UTC (permalink / raw)
  To: Dong Aisheng-B29396
  Cc: Liam Girdwood, kernel-janitors, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Wolfram Sang, alsa-devel, linux-kernel

From: Julia Lawall <julia@diku.dk>

Add a new variable for storing resources accessed subsequent to the one
accessed using request_mem_region, so the one accessed using
request_mem_region can be released if needed.

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

// <smpl>
@r@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@

if (E == NULL)
{
  ... when != if (E == NULL || ...) S1 else S2
      when != E = E1
*E->f
  ... when any
  return ...;
}
else S3
// </smpl>

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

---
Not even compile tested.

 sound/soc/mxs/mxs-saif.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index 401944c..76dc74d 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -617,7 +617,7 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
 
 static int mxs_saif_probe(struct platform_device *pdev)
 {
-	struct resource *res;
+	struct resource *iores, *dmares;
 	struct mxs_saif *saif;
 	struct mxs_saif_platform_data *pdata;
 	int ret = 0;
@@ -655,35 +655,36 @@ static int mxs_saif_probe(struct platform_device *pdev)
 		goto failed_clk;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
+	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!iores) {
 		ret = -ENODEV;
 		dev_err(&pdev->dev, "failed to get io resource: %d\n",
 			ret);
 		goto failed_get_resource;
 	}
 
-	if (!request_mem_region(res->start, resource_size(res), "mxs-saif")) {
+	if (!request_mem_region(iores->start, resource_size(iores),
+				"mxs-saif")) {
 		dev_err(&pdev->dev, "request_mem_region failed\n");
 		ret = -EBUSY;
 		goto failed_get_resource;
 	}
 
-	saif->base = ioremap(res->start, resource_size(res));
+	saif->base = ioremap(iores->start, resource_size(iores));
 	if (!saif->base) {
 		dev_err(&pdev->dev, "ioremap failed\n");
 		ret = -ENODEV;
 		goto failed_ioremap;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-	if (!res) {
+	dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+	if (!dmares) {
 		ret = -ENODEV;
 		dev_err(&pdev->dev, "failed to get dma resource: %d\n",
 			ret);
 		goto failed_ioremap;
 	}
-	saif->dma_param.chan_num = res->start;
+	saif->dma_param.chan_num = dmares->start;
 
 	saif->irq = platform_get_irq(pdev, 0);
 	if (saif->irq < 0) {
@@ -742,7 +743,7 @@ failed_get_irq2:
 failed_get_irq1:
 	iounmap(saif->base);
 failed_ioremap:
-	release_mem_region(res->start, resource_size(res));
+	release_mem_region(iores->start, resource_size(iores));
 failed_get_resource:
 	clk_put(saif->clk);
 failed_clk:

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

* Re: [alsa-devel] [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed
  2011-10-18 13:18   ` Julia Lawall
@ 2011-10-18 13:26     ` Mark Brown
  2011-10-18 13:29       ` Julia Lawall
  2011-10-18 14:10     ` Julia Lawall
  1 sibling, 1 reply; 7+ messages in thread
From: Mark Brown @ 2011-10-18 13:26 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Dong Aisheng-B29396, alsa-devel, Takashi Iwai, linux-kernel,
	kernel-janitors, Wolfram Sang, Liam Girdwood

On Tue, Oct 18, 2011 at 03:18:01PM +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Add a new variable for storing resources accessed subsequent to the one
> accessed using request_mem_region, so the one accessed using
> request_mem_region can be released if needed.

The same issue applies to all the patches in the series, adding a number
onto the end of the variable name to make the new one isn't ideal.

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

* Re: [alsa-devel] [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed
  2011-10-18 13:26     ` [alsa-devel] " Mark Brown
@ 2011-10-18 13:29       ` Julia Lawall
  0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2011-10-18 13:29 UTC (permalink / raw)
  To: Mark Brown
  Cc: Dong Aisheng-B29396, alsa-devel, Takashi Iwai, linux-kernel,
	kernel-janitors, Wolfram Sang, Liam Girdwood

On Tue, 18 Oct 2011, Mark Brown wrote:

> On Tue, Oct 18, 2011 at 03:18:01PM +0200, Julia Lawall wrote:
> > From: Julia Lawall <julia@diku.dk>
> > 
> > Add a new variable for storing resources accessed subsequent to the one
> > accessed using request_mem_region, so the one accessed using
> > request_mem_region can be released if needed.
> 
> The same issue applies to all the patches in the series, adding a number
> onto the end of the variable name to make the new one isn't ideal.

I put iores and dmares for the mxs code.  I will look and see if the same 
naming strategy can be used for the other two patches.

julia

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

* RE: [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed
  2011-10-18 13:18   ` Julia Lawall
  2011-10-18 13:26     ` [alsa-devel] " Mark Brown
@ 2011-10-18 14:10     ` Julia Lawall
  1 sibling, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2011-10-18 14:10 UTC (permalink / raw)
  To: Dong Aisheng-B29396
  Cc: Liam Girdwood, kernel-janitors, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Wolfram Sang, alsa-devel, linux-kernel

Actually, I have now sent another single patch that does the same for all 
5 files.

julia

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

end of thread, other threads:[~2011-10-18 14:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-18  3:45 [PATCH 1/3] sound/soc/mxs/mxs-saif.c: keep pointer to resource so it can be freed Julia Lawall
2011-10-18 13:01 ` Dong Aisheng-B29396
2011-10-18 13:06   ` Julia Lawall
2011-10-18 13:18   ` Julia Lawall
2011-10-18 13:26     ` [alsa-devel] " Mark Brown
2011-10-18 13:29       ` Julia Lawall
2011-10-18 14:10     ` Julia Lawall

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

all inboxes | Powered by JetHome®