linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] drivers/i2c/busses/i2c-au1550.c: Convert release_resource to release_region/release_mem_region
       [not found] <1297599132-7226-1-git-send-email-julia@diku.dk>
@ 2011-02-13 12:12 ` Julia Lawall
       [not found] ` <1297599132-7226-1-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2011-02-13 12:12 UTC (permalink / raw)
  To: ben-linux; +Cc: kernel-janitors, linux-i2c, linux-kernel

Request_region should be used with release_region, not release_resource.

The result of request_mem_region is no longer stored.  Instead the field
ioarea is used to store a pointer to the resource structure that contains
the start address.  This is the information that is needed later in
i2c_au1550_remove to release the region.  The field ioarea is not used for
anything else.

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

// <smpl>
@@
expression x,E;
@@
(
*x = request_region(...)
|
*x = request_mem_region(...)
)
... when != release_region(x)
    when != x = E
* release_resource(x);
// </smpl>

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

---
Not compiled due to incompatible architecture.

 drivers/i2c/busses/i2c-au1550.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 532828b..2ec78d7 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -389,13 +389,12 @@ i2c_au1550_probe(struct platform_device *pdev)
 		goto out;
 	}
 
-	priv->ioarea = request_mem_region(r->start, resource_size(r),
-					  pdev->name);
-	if (!priv->ioarea) {
+	if (!request_mem_region(r->start, resource_size(r), pdev->name)) {
 		ret = -EBUSY;
 		goto out_mem;
 	}
 
+	priv->ioarea = r;
 	priv->psc_base = CKSEG1ADDR(r->start);
 	priv->xfer_timeout = 200;
 	priv->ack_timeout = 200;
@@ -418,8 +417,7 @@ i2c_au1550_probe(struct platform_device *pdev)
 
 	i2c_au1550_disable(priv);
 
-	release_resource(priv->ioarea);
-	kfree(priv->ioarea);
+	release_mem_region(r->start, resource_size(r));
 out_mem:
 	kfree(priv);
 out:
@@ -430,12 +428,12 @@ static int __devexit
 i2c_au1550_remove(struct platform_device *pdev)
 {
 	struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
+	struct resource *r = priv->ioarea;
 
 	platform_set_drvdata(pdev, NULL);
 	i2c_del_adapter(&priv->adap);
 	i2c_au1550_disable(priv);
-	release_resource(priv->ioarea);
-	kfree(priv->ioarea);
+	release_mem_region(r->start, resource_size(r));
 	kfree(priv);
 	return 0;
 }

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

* [PATCH 5/5] drivers/i2c/busses/i2c-nuc900.c: Convert release_resource to release_region/release_mem_region
       [not found] ` <1297599132-7226-1-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
@ 2011-02-13 12:12   ` Julia Lawall
       [not found]     ` <1297599132-7226-6-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2011-02-13 12:12 UTC (permalink / raw)
  To: ben-linux-elnMNo+KYs3YtjvyW6yDsg
  Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Marek Vasut, Baruch Siach,
	Dave Airlie, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Request_region should be used with release_region, not release_resource.

The result of request_mem_region is no longer stored.  Instead the field
ioarea is used to store a pointer to the resource structure that contains
the start address.  This is the information that is needed later in
nuc900_i2c_remove to release the region.  The field ioarea is also printed
in some debugging code.

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

// <smpl>
@@
expression x,E;
@@
(
*x = request_region(...)
|
*x = request_mem_region(...)
)
... when != release_region(x)
    when != x = E
* release_resource(x);
// </smpl>

Signed-off-by: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>

---
Not compiled due to incompatible architecture.

 drivers/i2c/busses/i2c-nuc900.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/busses/i2c-nuc900.c b/drivers/i2c/busses/i2c-nuc900.c
index 7243426..97b16b7 100644
--- a/drivers/i2c/busses/i2c-nuc900.c
+++ b/drivers/i2c/busses/i2c-nuc900.c
@@ -568,15 +568,13 @@ static int __devinit nuc900_i2c_probe(struct platform_device *pdev)
 		goto err_clk;
 	}
 
-	i2c->ioarea = request_mem_region(res->start, resource_size(res),
-					 pdev->name);
-
-	if (i2c->ioarea == NULL) {
+	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
 		dev_err(&pdev->dev, "cannot request IO\n");
 		ret = -ENXIO;
 		goto err_clk;
 	}
 
+	i2c->ioarea = res;
 	i2c->regs = ioremap(res->start, resource_size(res));
 
 	if (i2c->regs == NULL) {
@@ -645,8 +643,7 @@ static int __devinit nuc900_i2c_probe(struct platform_device *pdev)
 	iounmap(i2c->regs);
 
  err_ioarea:
-	release_resource(i2c->ioarea);
-	kfree(i2c->ioarea);
+	release_mem_region(res->start, resource_size(res));
 
  err_clk:
 	clk_disable(i2c->clk);
@@ -665,6 +662,7 @@ static int __devinit nuc900_i2c_probe(struct platform_device *pdev)
 static int __devexit nuc900_i2c_remove(struct platform_device *pdev)
 {
 	struct nuc900_i2c *i2c = platform_get_drvdata(pdev);
+	struct resource *res = i2c->ioarea;
 
 	i2c_del_adapter(&i2c->adap);
 	free_irq(i2c->irq, i2c);
@@ -674,8 +672,7 @@ static int __devexit nuc900_i2c_remove(struct platform_device *pdev)
 
 	iounmap(i2c->regs);
 
-	release_resource(i2c->ioarea);
-	kfree(i2c->ioarea);
+	release_mem_region(res->start, resource_size(res));
 	kfree(i2c);
 
 	return 0;

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

* Re: [PATCH 5/5] drivers/i2c/busses/i2c-nuc900.c: Convert release_resource to release_region/release_mem_region
       [not found]     ` <1297599132-7226-6-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
@ 2011-02-14 16:56       ` Marek Vasut
       [not found]         ` <201102141756.19068.marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2011-02-14 16:56 UTC (permalink / raw)
  To: Julia Lawall
  Cc: ben-linux-elnMNo+KYs3YtjvyW6yDsg,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Baruch Siach, Dave Airlie,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Sunday 13 February 2011 13:12:12 Julia Lawall wrote:
> Request_region should be used with release_region, not release_resource.
> 
> The result of request_mem_region is no longer stored.  Instead the field
> ioarea is used to store a pointer to the resource structure that contains
> the start address.  This is the information that is needed later in
> nuc900_i2c_remove to release the region.  The field ioarea is also printed
> in some debugging code.
> 
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression x,E;
> @@
> (
> *x = request_region(...)
> 
> *x = request_mem_region(...)
> )
> ... when != release_region(x)
>     when != x = E
> * release_resource(x);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>
> 
> ---
> Not compiled due to incompatible architecture.
> 
>  drivers/i2c/busses/i2c-nuc900.c |   13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-nuc900.c
> b/drivers/i2c/busses/i2c-nuc900.c index 7243426..97b16b7 100644
> --- a/drivers/i2c/busses/i2c-nuc900.c
> +++ b/drivers/i2c/busses/i2c-nuc900.c
> @@ -568,15 +568,13 @@ static int __devinit nuc900_i2c_probe(struct
> platform_device *pdev) goto err_clk;
>  	}
> 
> -	i2c->ioarea = request_mem_region(res->start, resource_size(res),
> -					 pdev->name);
> -
> -	if (i2c->ioarea == NULL) {
> +	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {

I prefer the original version here -- it's clearer and also, doesn't the new 
version violate line-over-80 principle ?

>  		dev_err(&pdev->dev, "cannot request IO\n");
>  		ret = -ENXIO;
>  		goto err_clk;
>  	}
> 
> +	i2c->ioarea = res;
>  	i2c->regs = ioremap(res->start, resource_size(res));
> 
>  	if (i2c->regs == NULL) {
> @@ -645,8 +643,7 @@ static int __devinit nuc900_i2c_probe(struct
> platform_device *pdev) iounmap(i2c->regs);
> 
>   err_ioarea:
> -	release_resource(i2c->ioarea);
> -	kfree(i2c->ioarea);
> +	release_mem_region(res->start, resource_size(res));
> 
>   err_clk:
>  	clk_disable(i2c->clk);
> @@ -665,6 +662,7 @@ static int __devinit nuc900_i2c_probe(struct
> platform_device *pdev) static int __devexit nuc900_i2c_remove(struct
> platform_device *pdev) {
>  	struct nuc900_i2c *i2c = platform_get_drvdata(pdev);
> +	struct resource *res = i2c->ioarea;

No need for this ...
> 
>  	i2c_del_adapter(&i2c->adap);
>  	free_irq(i2c->irq, i2c);
> @@ -674,8 +672,7 @@ static int __devexit nuc900_i2c_remove(struct
> platform_device *pdev)
> 
>  	iounmap(i2c->regs);
> 
> -	release_resource(i2c->ioarea);
> -	kfree(i2c->ioarea);

... the i2c pointer is still available here, why introducing struct resource 
*res. release_mem_region() looks like a sane change to me though.

> +	release_mem_region(res->start, resource_size(res));
>  	kfree(i2c);
> 
>  	return 0;

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

* Re: [PATCH 5/5] drivers/i2c/busses/i2c-nuc900.c: Convert release_resource to release_region/release_mem_region
       [not found]         ` <201102141756.19068.marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-02-14 17:04           ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2011-02-14 17:04 UTC (permalink / raw)
  To: Marek Vasut
  Cc: ben-linux-elnMNo+KYs3YtjvyW6yDsg,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Baruch Siach, Dave Airlie,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Mon, 14 Feb 2011, Marek Vasut wrote:

> On Sunday 13 February 2011 13:12:12 Julia Lawall wrote:
> > Request_region should be used with release_region, not release_resource.
> > 
> > The result of request_mem_region is no longer stored.  Instead the field
> > ioarea is used to store a pointer to the resource structure that contains
> > the start address.  This is the information that is needed later in
> > nuc900_i2c_remove to release the region.  The field ioarea is also printed
> > in some debugging code.
> > 
> > The semantic match that finds this problem is as follows:
> > (http://coccinelle.lip6.fr/)
> > 
> > // <smpl>
> > @@
> > expression x,E;
> > @@
> > (
> > *x = request_region(...)
> > 
> > *x = request_mem_region(...)
> > )
> > ... when != release_region(x)
> >     when != x = E
> > * release_resource(x);
> > // </smpl>
> > 
> > Signed-off-by: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>
> > 
> > ---
> > Not compiled due to incompatible architecture.
> > 
> >  drivers/i2c/busses/i2c-nuc900.c |   13 +++++--------
> >  1 file changed, 5 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-nuc900.c
> > b/drivers/i2c/busses/i2c-nuc900.c index 7243426..97b16b7 100644
> > --- a/drivers/i2c/busses/i2c-nuc900.c
> > +++ b/drivers/i2c/busses/i2c-nuc900.c
> > @@ -568,15 +568,13 @@ static int __devinit nuc900_i2c_probe(struct
> > platform_device *pdev) goto err_clk;
> >  	}
> > 
> > -	i2c->ioarea = request_mem_region(res->start, resource_size(res),
> > -					 pdev->name);
> > -
> > -	if (i2c->ioarea == NULL) {
> > +	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
> 
> I prefer the original version here -- it's clearer and also, doesn't the new 
> version violate line-over-80 principle ?

The line ends before column 80.

I'm not sure that the result of request_mem_region is the proper argment 
to give to release_region.  In any case, all of the other calls to 
request_mem_region that do use release_region do not use the return value.  
They just test it directly as I have done here.

julia

> >  		dev_err(&pdev->dev, "cannot request IO\n");
> >  		ret = -ENXIO;
> >  		goto err_clk;
> >  	}
> > 
> > +	i2c->ioarea = res;
> >  	i2c->regs = ioremap(res->start, resource_size(res));
> > 
> >  	if (i2c->regs == NULL) {
> > @@ -645,8 +643,7 @@ static int __devinit nuc900_i2c_probe(struct
> > platform_device *pdev) iounmap(i2c->regs);
> > 
> >   err_ioarea:
> > -	release_resource(i2c->ioarea);
> > -	kfree(i2c->ioarea);
> > +	release_mem_region(res->start, resource_size(res));
> > 
> >   err_clk:
> >  	clk_disable(i2c->clk);
> > @@ -665,6 +662,7 @@ static int __devinit nuc900_i2c_probe(struct
> > platform_device *pdev) static int __devexit nuc900_i2c_remove(struct
> > platform_device *pdev) {
> >  	struct nuc900_i2c *i2c = platform_get_drvdata(pdev);
> > +	struct resource *res = i2c->ioarea;
> 
> No need for this ...
> > 
> >  	i2c_del_adapter(&i2c->adap);
> >  	free_irq(i2c->irq, i2c);
> > @@ -674,8 +672,7 @@ static int __devexit nuc900_i2c_remove(struct
> > platform_device *pdev)
> > 
> >  	iounmap(i2c->regs);
> > 
> > -	release_resource(i2c->ioarea);
> > -	kfree(i2c->ioarea);
> 
> ... the i2c pointer is still available here, why introducing struct resource 
> *res. release_mem_region() looks like a sane change to me though.
> 
> > +	release_mem_region(res->start, resource_size(res));
> >  	kfree(i2c);
> > 
> >  	return 0;
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

end of thread, other threads:[~2011-02-14 17:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1297599132-7226-1-git-send-email-julia@diku.dk>
2011-02-13 12:12 ` [PATCH 1/5] drivers/i2c/busses/i2c-au1550.c: Convert release_resource to release_region/release_mem_region Julia Lawall
     [not found] ` <1297599132-7226-1-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
2011-02-13 12:12   ` [PATCH 5/5] drivers/i2c/busses/i2c-nuc900.c: " Julia Lawall
     [not found]     ` <1297599132-7226-6-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
2011-02-14 16:56       ` Marek Vasut
     [not found]         ` <201102141756.19068.marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-02-14 17:04           ` 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).