From: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Magnus Damm <magnus.damm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Wolfram Sang
<wsa+renesas-jBu1N2QxHDJrcw3mvpCnnVaTQe2KTcn/@public.gmane.org>
Subject: [PATCH 6/6] i2c: sh_mobile: devm conversion, irq setup
Date: Thu, 1 May 2014 00:21:10 +0200 [thread overview]
Message-ID: <1398896470-24663-7-git-send-email-wsa@the-dreams.de> (raw)
In-Reply-To: <1398896470-24663-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
From: Wolfram Sang <wsa+renesas-jBu1N2QxHDJrcw3mvpCnnVaTQe2KTcn/@public.gmane.org>
This is what devm was made for. No rollback mechanism needed, remove the
hook parameter from the irq setup function and simplify it. While we are
here change some variables to proper types.
Signed-off-by: Wolfram Sang <wsa+renesas-jBu1N2QxHDJrcw3mvpCnnVaTQe2KTcn/@public.gmane.org>
---
drivers/i2c/busses/i2c-sh_mobile.c | 56 ++++++++++----------------------------
1 file changed, 15 insertions(+), 41 deletions(-)
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index c47d11493b97..ddc9970fd724 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -611,42 +611,25 @@ static struct i2c_algorithm sh_mobile_i2c_algorithm = {
.master_xfer = sh_mobile_i2c_xfer,
};
-static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
+static int sh_mobile_i2c_hook_irqs(struct platform_device *dev)
{
struct resource *res;
- int ret = -ENXIO;
- int n, k = 0;
+ resource_size_t n;
+ int k = 0, ret;
while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
- for (n = res->start; hook && n <= res->end; n++) {
- if (request_irq(n, sh_mobile_i2c_isr, 0,
- dev_name(&dev->dev), dev)) {
- for (n--; n >= res->start; n--)
- free_irq(n, dev);
-
- goto rollback;
+ for (n = res->start; n <= res->end; n++) {
+ ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr,
+ 0, dev_name(&dev->dev), dev);
+ if (ret) {
+ dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
+ return ret;
}
}
k++;
}
- if (hook)
- return k > 0 ? 0 : -ENOENT;
-
- ret = 0;
-
- rollback:
- k--;
-
- while (k >= 0) {
- res = platform_get_resource(dev, IORESOURCE_IRQ, k);
- for (n = res->start; n <= res->end; n++)
- free_irq(n, dev);
-
- k--;
- }
-
- return ret;
+ return k > 0 ? 0 : -ENOENT;
}
static int sh_mobile_i2c_probe(struct platform_device *dev)
@@ -668,11 +651,9 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
return PTR_ERR(pd->clk);
}
- ret = sh_mobile_i2c_hook_irqs(dev, 1);
- if (ret) {
- dev_err(&dev->dev, "cannot request IRQ\n");
+ ret = sh_mobile_i2c_hook_irqs(dev);
+ if (ret)
return ret;
- }
pd->dev = &dev->dev;
platform_set_drvdata(dev, pd);
@@ -680,10 +661,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
pd->reg = devm_ioremap_resource(&dev->dev, res);
- if (IS_ERR(pd->reg)) {
- ret = PTR_ERR(pd->reg);
- goto err_irq;
- }
+ if (IS_ERR(pd->reg))
+ return PTR_ERR(pd->reg);
/* Use platform data bus speed or STANDARD_MODE */
ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed);
@@ -735,7 +714,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
ret = i2c_add_numbered_adapter(adap);
if (ret < 0) {
dev_err(&dev->dev, "cannot add numbered adapter\n");
- goto err_irq;
+ return ret;
}
dev_info(&dev->dev,
@@ -743,10 +722,6 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
adap->nr, pd->bus_speed, pd->iccl, pd->icch);
return 0;
-
- err_irq:
- sh_mobile_i2c_hook_irqs(dev, 0);
- return ret;
}
static int sh_mobile_i2c_remove(struct platform_device *dev)
@@ -754,7 +729,6 @@ static int sh_mobile_i2c_remove(struct platform_device *dev)
struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
i2c_del_adapter(&pd->adap);
- sh_mobile_i2c_hook_irqs(dev, 0);
pm_runtime_disable(&dev->dev);
return 0;
}
--
1.9.2
next prev parent reply other threads:[~2014-04-30 22:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-30 22:21 [PATCH 0/6] i2c: sh_mobile: cleanups Wolfram Sang
2014-04-30 22:21 ` [PATCH 1/6] i2c: sh_mobile: replace magic hex values with constants Wolfram Sang
2014-04-30 22:21 ` [PATCH 2/6] i2c: sh_mobile: improve error handling Wolfram Sang
[not found] ` <1398896470-24663-3-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2014-04-30 22:25 ` Geert Uytterhoeven
2014-05-02 7:19 ` Wolfram Sang
2014-04-30 22:21 ` [PATCH 3/6] i2c: sh_mobile: honor DT bus speed settings Wolfram Sang
[not found] ` <1398896470-24663-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2014-04-30 22:21 ` [PATCH 4/6] i2c: sh_mobile: add devicetree documentation Wolfram Sang
2014-04-30 22:32 ` Geert Uytterhoeven
2014-05-01 1:02 ` Rob Herring
2014-05-02 7:23 ` Wolfram Sang
2014-04-30 22:21 ` Wolfram Sang [this message]
2014-04-30 22:44 ` [PATCH 6/6] i2c: sh_mobile: devm conversion, irq setup Geert Uytterhoeven
2014-04-30 22:21 ` [PATCH 5/6] i2c: sh_mobile: devm conversion, low hanging fruits Wolfram Sang
2014-04-30 22:39 ` Geert Uytterhoeven
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=1398896470-24663-7-git-send-email-wsa@the-dreams.de \
--to=wsa-z923lk4zbo2bacvfa/9k2g@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=magnus.damm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=wsa+renesas-jBu1N2QxHDJrcw3mvpCnnVaTQe2KTcn/@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).