linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] i2c: davinci: update to devm_* API
@ 2013-02-06 11:22 Vishwanathrao Badarkhe, Manish
  2013-02-06 11:51 ` Sergei Shtylyov
  0 siblings, 1 reply; 3+ messages in thread
From: Vishwanathrao Badarkhe, Manish @ 2013-02-06 11:22 UTC (permalink / raw)
  To: linux-i2c, davinci-linux-open-source, linux-kernel
  Cc: nsekhar, khilman, ben-linux, w.sang, manishv.b

Update the code to use devm_* API so that driver
core will manage resources.

Signed-off-by: Vishwanathrao Badarkhe, Manish <manishv.b@ti.com>
---
Changes since V1:
  - Rebase on top of v3.8-rc6 of linus tree.
  - Apply devm operation on clk_get.
 
:100644 100644 6a0a553... da4e218... M	drivers/i2c/busses/i2c-davinci.c
 drivers/i2c/busses/i2c-davinci.c |   45 +++++++++++---------------------------
 1 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 6a0a553..da4e218 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -643,7 +643,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 {
 	struct davinci_i2c_dev *dev;
 	struct i2c_adapter *adap;
-	struct resource *mem, *irq, *ioarea;
+	struct resource *mem, *irq;
 	int r;
 
 	/* NOTE: driver uses the static register mapping */
@@ -659,17 +659,11 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	ioarea = request_mem_region(mem->start, resource_size(mem),
-				    pdev->name);
-	if (!ioarea) {
-		dev_err(&pdev->dev, "I2C region already claimed\n");
-		return -EBUSY;
-	}
-
-	dev = kzalloc(sizeof(struct davinci_i2c_dev), GFP_KERNEL);
+	dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_i2c_dev),
+			GFP_KERNEL);
 	if (!dev) {
-		r = -ENOMEM;
-		goto err_release_region;
+		dev_err(&pdev->dev, "Memory allocation failed\n");
+		return -ENOMEM;
 	}
 
 	init_completion(&dev->cmd_complete);
@@ -699,22 +693,24 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 		dev->pdata = &davinci_i2c_platform_data_default;
 	}
 
-	dev->clk = clk_get(&pdev->dev, NULL);
+	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk)) {
 		r = -ENODEV;
 		goto err_free_mem;
 	}
 	clk_prepare_enable(dev->clk);
 
-	dev->base = ioremap(mem->start, resource_size(mem));
+	dev->base = devm_request_and_ioremap(&pdev->dev, mem);
 	if (!dev->base) {
 		r = -EBUSY;
-		goto err_mem_ioremap;
+		dev_err(&pdev->dev, "I2C region already claimed\n");
+		goto err_unuse_clocks;
 	}
 
 	i2c_davinci_init(dev);
 
-	r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev);
+	r = devm_request_irq(&pdev->dev, dev->irq, i2c_davinci_isr, 0,
+			pdev->name, dev);
 	if (r) {
 		dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
 		goto err_unuse_clocks;
@@ -723,7 +719,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	r = i2c_davinci_cpufreq_register(dev);
 	if (r) {
 		dev_err(&pdev->dev, "failed to register cpufreq\n");
-		goto err_free_irq;
+		goto err_unuse_clocks;
 	}
 
 	adap = &dev->adapter;
@@ -740,26 +736,18 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	r = i2c_add_numbered_adapter(adap);
 	if (r) {
 		dev_err(&pdev->dev, "failure adding adapter\n");
-		goto err_free_irq;
+		goto err_unuse_clocks;
 	}
 	of_i2c_register_devices(adap);
 
 	return 0;
 
-err_free_irq:
-	free_irq(dev->irq, dev);
 err_unuse_clocks:
-	iounmap(dev->base);
-err_mem_ioremap:
 	clk_disable_unprepare(dev->clk);
-	clk_put(dev->clk);
 	dev->clk = NULL;
 err_free_mem:
 	platform_set_drvdata(pdev, NULL);
 	put_device(&pdev->dev);
-	kfree(dev);
-err_release_region:
-	release_mem_region(mem->start, resource_size(mem));
 
 	return r;
 }
@@ -767,7 +755,6 @@ err_release_region:
 static int davinci_i2c_remove(struct platform_device *pdev)
 {
 	struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
-	struct resource *mem;
 
 	i2c_davinci_cpufreq_deregister(dev);
 
@@ -776,16 +763,10 @@ static int davinci_i2c_remove(struct platform_device *pdev)
 	put_device(&pdev->dev);
 
 	clk_disable_unprepare(dev->clk);
-	clk_put(dev->clk);
 	dev->clk = NULL;
 
 	davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
-	free_irq(dev->irq, dev);
-	iounmap(dev->base);
-	kfree(dev);
 
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	release_mem_region(mem->start, resource_size(mem));
 	return 0;
 }
 
-- 
1.7.4.1


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

* Re: [PATCH V2] i2c: davinci: update to devm_* API
  2013-02-06 11:22 [PATCH V2] i2c: davinci: update to devm_* API Vishwanathrao Badarkhe, Manish
@ 2013-02-06 11:51 ` Sergei Shtylyov
  2013-02-07  3:02   ` Vishwanathrao Badarkhe, Manish
  0 siblings, 1 reply; 3+ messages in thread
From: Sergei Shtylyov @ 2013-02-06 11:51 UTC (permalink / raw)
  To: Vishwanathrao Badarkhe, Manish
  Cc: linux-i2c, davinci-linux-open-source, linux-kernel, w.sang, ben-linux

Hello.

On 06-02-2013 15:22, Vishwanathrao Badarkhe, Manish wrote:

> Update the code to use devm_* API so that driver
> core will manage resources.

> Signed-off-by: Vishwanathrao Badarkhe, Manish <manishv.b@ti.com>
> ---
> Changes since V1:
>    - Rebase on top of v3.8-rc6 of linus tree.
>    - Apply devm operation on clk_get.

> :100644 100644 6a0a553... da4e218... M	drivers/i2c/busses/i2c-davinci.c
>   drivers/i2c/busses/i2c-davinci.c |   45 +++++++++++---------------------------
>   1 files changed, 13 insertions(+), 32 deletions(-)

> diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
> index 6a0a553..da4e218 100644
> --- a/drivers/i2c/busses/i2c-davinci.c
> +++ b/drivers/i2c/busses/i2c-davinci.c
[...]
> @@ -699,22 +693,24 @@ static int davinci_i2c_probe(struct platform_device *pdev)
>   		dev->pdata = &davinci_i2c_platform_data_default;
>   	}
>
> -	dev->clk = clk_get(&pdev->dev, NULL);
> +	dev->clk = devm_clk_get(&pdev->dev, NULL);
>   	if (IS_ERR(dev->clk)) {
>   		r = -ENODEV;
>   		goto err_free_mem;
>   	}
>   	clk_prepare_enable(dev->clk);
>
> -	dev->base = ioremap(mem->start, resource_size(mem));
> +	dev->base = devm_request_and_ioremap(&pdev->dev, mem);
>   	if (!dev->base) {
>   		r = -EBUSY;

    Comment to devm_request_and_ioremap() suggests returning -EADDRNOTAVAIL on 
failure. -EBUSY wasn't the right code even before this change, should have 
been -ENOMEM.

WBR, Sergei


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

* RE: [PATCH V2] i2c: davinci: update to devm_* API
  2013-02-06 11:51 ` Sergei Shtylyov
@ 2013-02-07  3:02   ` Vishwanathrao Badarkhe, Manish
  0 siblings, 0 replies; 3+ messages in thread
From: Vishwanathrao Badarkhe, Manish @ 2013-02-07  3:02 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: linux-i2c, davinci-linux-open-source, linux-kernel, w.sang, ben-linux

Hi Sergei,

On Wed, Feb 06, 2013 at 17:21:36, Sergei Shtylyov wrote:
> Hello.
> 
> On 06-02-2013 15:22, Vishwanathrao Badarkhe, Manish wrote:
> 
> > Update the code to use devm_* API so that driver core will manage 
> > resources.
> 
> > Signed-off-by: Vishwanathrao Badarkhe, Manish <manishv.b@ti.com>
> > ---
> > Changes since V1:
> >    - Rebase on top of v3.8-rc6 of linus tree.
> >    - Apply devm operation on clk_get.
> 
> > :100644 100644 6a0a553... da4e218... M	drivers/i2c/busses/i2c-davinci.c
> >   drivers/i2c/busses/i2c-davinci.c |   45 +++++++++++---------------------------
> >   1 files changed, 13 insertions(+), 32 deletions(-)
> 
> > diff --git a/drivers/i2c/busses/i2c-davinci.c 
> > b/drivers/i2c/busses/i2c-davinci.c
> > index 6a0a553..da4e218 100644
> > --- a/drivers/i2c/busses/i2c-davinci.c
> > +++ b/drivers/i2c/busses/i2c-davinci.c
> [...]
> > @@ -699,22 +693,24 @@ static int davinci_i2c_probe(struct platform_device *pdev)
> >   		dev->pdata = &davinci_i2c_platform_data_default;
> >   	}
> >
> > -	dev->clk = clk_get(&pdev->dev, NULL);
> > +	dev->clk = devm_clk_get(&pdev->dev, NULL);
> >   	if (IS_ERR(dev->clk)) {
> >   		r = -ENODEV;
> >   		goto err_free_mem;
> >   	}
> >   	clk_prepare_enable(dev->clk);
> >
> > -	dev->base = ioremap(mem->start, resource_size(mem));
> > +	dev->base = devm_request_and_ioremap(&pdev->dev, mem);
> >   	if (!dev->base) {
> >   		r = -EBUSY;
> 
>     Comment to devm_request_and_ioremap() suggests returning -EADDRNOTAVAIL on failure. -EBUSY wasn't the right code even before this change, should have been -ENOMEM.

Oh, you are right. I will change this to -EADDRNOTAVAIL. Thanks for 
pointing this out.

Thanks, 
Manish Badarkhe

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

end of thread, other threads:[~2013-02-07  3:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-06 11:22 [PATCH V2] i2c: davinci: update to devm_* API Vishwanathrao Badarkhe, Manish
2013-02-06 11:51 ` Sergei Shtylyov
2013-02-07  3:02   ` Vishwanathrao Badarkhe, Manish

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