From: Jingoo Han <jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
To: 'Wolfram Sang' <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
'Jingoo Han' <jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
'Vitaly Wool'
<vitalywool-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
'Roland Stigge' <stigge-uj/7R2tJ6VmzQB+pC5nmwQ@public.gmane.org>
Subject: [PATCH V2 07/13] i2c: pnx: Use devm_*() functions
Date: Mon, 06 Jan 2014 11:39:29 +0900 [thread overview]
Message-ID: <008b01cf0a88$85df55f0$919e01d0$%han@samsung.com> (raw)
In-Reply-To: <002b01cefaf4$fa737d40$ef5a77c0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Use devm_*() functions to make cleanup paths simpler.
Signed-off-by: Jingoo Han <jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
---
Changes since V1:
- Use devm_ioremap_resource() to make the code simpler, per Wolfram Sang.
drivers/i2c/busses/i2c-pnx.c | 60 ++++++++++--------------------------------
1 file changed, 14 insertions(+), 46 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index c9a352f..5f9cb2d 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -628,11 +628,9 @@ static int i2c_pnx_probe(struct platform_device *pdev)
struct resource *res;
u32 speed = I2C_PNX_SPEED_KHZ_DEFAULT * 1000;
- alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL);
- if (!alg_data) {
- ret = -ENOMEM;
- goto err_kzalloc;
- }
+ alg_data = devm_kzalloc(&pdev->dev, sizeof(*alg_data), GFP_KERNEL);
+ if (!alg_data)
+ return -ENOMEM;
platform_set_drvdata(pdev, alg_data);
@@ -657,11 +655,9 @@ static int i2c_pnx_probe(struct platform_device *pdev)
*/
}
#endif
- alg_data->clk = clk_get(&pdev->dev, NULL);
- if (IS_ERR(alg_data->clk)) {
- ret = PTR_ERR(alg_data->clk);
- goto out_drvdata;
- }
+ alg_data->clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(alg_data->clk))
+ return PTR_ERR(alg_data->clk);
init_timer(&alg_data->mif.timer);
alg_data->mif.timer.function = i2c_pnx_timeout;
@@ -674,29 +670,17 @@ static int i2c_pnx_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "Unable to get mem resource.\n");
- ret = -EBUSY;
- goto out_clkget;
- }
- if (!request_mem_region(res->start, I2C_PNX_REGION_SIZE,
- pdev->name)) {
- dev_err(&pdev->dev,
- "I/O region 0x%08x for I2C already in use.\n",
- res->start);
- ret = -ENOMEM;
- goto out_clkget;
+ return -EBUSY;
}
alg_data->base = res->start;
- alg_data->ioaddr = ioremap(res->start, I2C_PNX_REGION_SIZE);
- if (!alg_data->ioaddr) {
- dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n");
- ret = -ENOMEM;
- goto out_release;
- }
+ alg_data->ioaddr = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(alg_data->ioaddr))
+ return PTR_ERR(alg_data->ioaddr);
ret = clk_enable(alg_data->clk);
if (ret)
- goto out_unmap;
+ return ret;
freq = clk_get_rate(alg_data->clk);
@@ -730,8 +714,8 @@ static int i2c_pnx_probe(struct platform_device *pdev)
ret = alg_data->irq;
goto out_clock;
}
- ret = request_irq(alg_data->irq, i2c_pnx_interrupt,
- 0, pdev->name, alg_data);
+ ret = devm_request_irq(&pdev->dev, alg_data->irq, i2c_pnx_interrupt,
+ 0, pdev->name, alg_data);
if (ret)
goto out_clock;
@@ -739,7 +723,7 @@ static int i2c_pnx_probe(struct platform_device *pdev)
ret = i2c_add_numbered_adapter(&alg_data->adapter);
if (ret < 0) {
dev_err(&pdev->dev, "I2C: Failed to add bus\n");
- goto out_irq;
+ goto out_clock;
}
dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
@@ -747,19 +731,8 @@ static int i2c_pnx_probe(struct platform_device *pdev)
return 0;
-out_irq:
- free_irq(alg_data->irq, alg_data);
out_clock:
clk_disable(alg_data->clk);
-out_unmap:
- iounmap(alg_data->ioaddr);
-out_release:
- release_mem_region(res->start, I2C_PNX_REGION_SIZE);
-out_clkget:
- clk_put(alg_data->clk);
-out_drvdata:
- kfree(alg_data);
-err_kzalloc:
return ret;
}
@@ -767,13 +740,8 @@ static int i2c_pnx_remove(struct platform_device *pdev)
{
struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
- free_irq(alg_data->irq, alg_data);
i2c_del_adapter(&alg_data->adapter);
clk_disable(alg_data->clk);
- iounmap(alg_data->ioaddr);
- release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
- clk_put(alg_data->clk);
- kfree(alg_data);
return 0;
}
--
1.7.10.4
next prev parent reply other threads:[~2014-01-06 2:39 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-17 6:45 [PATCH 00/13] i2c: Use devm_*() functions Jingoo Han
[not found] ` <001601cefaf3$940d0040$bc2700c0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-12-17 6:46 ` [PATCH 01/13] i2c: bcm2835: Use devm_request_irq() Jingoo Han
[not found] ` <001d01cefaf3$b743e4c0$25cbae40$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-12-18 2:21 ` Stephen Warren
[not found] ` <52B10691.2010105-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-12-18 4:15 ` Jingoo Han
[not found] ` <000601cefba7$d13450e0$739cf2a0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-01-04 21:06 ` Wolfram Sang
2013-12-17 6:48 ` [PATCH 02/13] i2c: gpio: Use devm_gpio_request() Jingoo Han
[not found] ` <001e01cefaf3$f8b520e0$ea1f62a0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-05-21 10:59 ` Wolfram Sang
2013-12-17 6:50 ` [PATCH 03/13] i2c: highlander: Use devm_*() functions Jingoo Han
2013-12-17 6:51 ` [PATCH 04/13] i2c: isch: Use devm_request_region() Jingoo Han
[not found] ` <002801cefaf4$69243d70$3b6cb850$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-12-17 7:53 ` Jean Delvare
[not found] ` <20131217085309.1459ea27-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-12-18 1:42 ` Jingoo Han
[not found] ` <007401cefb92$6f521390$4df63ab0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-12-18 6:39 ` Jean Delvare
2013-12-18 1:48 ` [PATCH V2 " Jingoo Han
[not found] ` <007501cefb93$32ca0df0$985e29d0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-12-18 7:46 ` Jean Delvare
2014-01-04 21:23 ` Wolfram Sang
2013-12-17 6:53 ` [PATCH 05/13] i2c: mv64xxx: Use devm_request_irq() Jingoo Han
2013-12-17 6:54 ` [PATCH 06/13] i2c: pmcmsp: Use devm_*() functions Jingoo Han
2013-12-17 6:55 ` [PATCH 07/13] i2c: pnx: " Jingoo Han
[not found] ` <002b01cefaf4$fa737d40$ef5a77c0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-12-17 12:30 ` Roland Stigge
2014-01-04 21:07 ` Wolfram Sang
2014-01-06 2:39 ` Jingoo Han [this message]
[not found] ` <008b01cf0a88$85df55f0$919e01d0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-01-06 11:23 ` [PATCH V2 " Roland Stigge
2014-01-09 21:24 ` Wolfram Sang
2014-01-10 0:34 ` Jingoo Han
[not found] ` <001f01cf0d9b$aba03910$02e0ab30$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-01-13 12:29 ` Wolfram Sang
2014-01-14 0:09 ` Jingoo Han
2013-12-17 6:57 ` [PATCH 08/13] i2c: pxa: " Jingoo Han
2013-12-17 6:58 ` [PATCH 09/13] i2c: simtec: " Jingoo Han
2013-12-17 7:00 ` [PATCH 10/13] i2c: sirf: Use devm_clk_get() Jingoo Han
2013-12-17 7:00 ` [PATCH 11/13] i2c: versatile: Use devm_*() functions Jingoo Han
2013-12-17 7:01 ` [PATCH 12/13] i2c: viperboard: Use devm_kzalloc() functions Jingoo Han
[not found] ` <003001cefaf5$d6618590$832490b0$%han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-12-19 13:05 ` Lars Poeschel
2014-01-04 21:16 ` Wolfram Sang
2013-12-17 7:02 ` [PATCH 13/13] i2c: xiic: Use devm_*() functions Jingoo Han
2014-04-30 13:28 ` [PATCH 02/13] i2c: gpio: Use devm_gpio_request() Violeta Menendez Gonzalez
[not found] ` <5360FA98.3030503-4yDnlxn2s6sWdaTGBSpHTA@public.gmane.org>
2014-05-21 10:56 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='008b01cf0a88$85df55f0$919e01d0$%han@samsung.com' \
--to=jg1.han-sze3o3uu22jbdgjk7y7tuq@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=stigge-uj/7R2tJ6VmzQB+pC5nmwQ@public.gmane.org \
--cc=vitalywool-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).