From: Ben Dooks <ben-linux@fluff.org>
To: wim@iguana.be, linux-kernel@vger.kernel.org
Subject: [PATCH] watchdog: cleanup s3c2410_wdt probe and release
Date: Mon, 18 Dec 2006 10:31:32 +0000 [thread overview]
Message-ID: <20061218103132.GA10691@home.fluff.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 3027 bytes --]
Cleanup the s3c2410_wdt driver's exit point by
using labels instead of multiple returns. Also
remove the checks for the resources having been
allocate in the exit, as we will now either have
fully allocated or not allocated the resources
at-all.
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
diff -urpN -X ../dontdiff linux-2.6.20-rc1/drivers/char/watchdog/s3c2410_wdt.c linux-2.6.20-rc1-fix2/drivers/char/watchdog/s3c2410_wdt.c
--- linux-2.6.20-rc1/drivers/char/watchdog/s3c2410_wdt.c 2006-11-29 21:57:37.000000000 +0000
+++ linux-2.6.20-rc1-fix2/drivers/char/watchdog/s3c2410_wdt.c 2006-12-18 10:26:55.000000000 +0000
@@ -366,13 +366,15 @@ static int s3c2410wdt_probe(struct platf
wdt_mem = request_mem_region(res->start, size, pdev->name);
if (wdt_mem == NULL) {
printk(KERN_INFO PFX "failed to get memory region\n");
- return -ENOENT;
+ ret = -ENOENT;
+ goto err_req;
}
wdt_base = ioremap(res->start, size);
if (wdt_base == 0) {
printk(KERN_INFO PFX "failed to ioremap() region\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_req;
}
DBG("probe: mapped wdt_base=%p\n", wdt_base);
@@ -380,22 +382,21 @@ static int s3c2410wdt_probe(struct platf
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (res == NULL) {
printk(KERN_INFO PFX "failed to get irq resource\n");
- iounmap(wdt_base);
- return -ENOENT;
+ ret = -ENOENT;
+ goto err_map;
}
ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, pdev);
if (ret != 0) {
printk(KERN_INFO PFX "failed to install irq (%d)\n", ret);
- iounmap(wdt_base);
- return ret;
+ goto err_map;
}
wdt_clock = clk_get(&pdev->dev, "watchdog");
if (wdt_clock == NULL) {
printk(KERN_INFO PFX "failed to find watchdog clock source\n");
- iounmap(wdt_base);
- return -ENOENT;
+ ret = -ENOENT;
+ goto err_irq;
}
clk_enable(wdt_clock);
@@ -418,8 +419,7 @@ static int s3c2410wdt_probe(struct platf
if (ret) {
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (%d)\n",
WATCHDOG_MINOR, ret);
- iounmap(wdt_base);
- return ret;
+ goto err_clk;
}
if (tmr_atboot && started == 0) {
@@ -434,26 +434,36 @@ static int s3c2410wdt_probe(struct platf
}
return 0;
+
+ err_clk:
+ clk_disable(wdt_clock);
+ clk_put(wdt_clock);
+
+ err_irq:
+ free_irq(wdt_irq->start, pdev);
+
+ err_map:
+ iounmap(wdt_base);
+
+ err_req:
+ release_resource(wdt_mem);
+ kfree(wdt_mem);
+
+ return ret;
}
static int s3c2410wdt_remove(struct platform_device *dev)
{
- if (wdt_mem != NULL) {
- release_resource(wdt_mem);
- kfree(wdt_mem);
- wdt_mem = NULL;
- }
-
- if (wdt_irq != NULL) {
- free_irq(wdt_irq->start, dev);
- wdt_irq = NULL;
- }
-
- if (wdt_clock != NULL) {
- clk_disable(wdt_clock);
- clk_put(wdt_clock);
- wdt_clock = NULL;
- }
+ release_resource(wdt_mem);
+ kfree(wdt_mem);
+ wdt_mem = NULL;
+
+ free_irq(wdt_irq->start, dev);
+ wdt_irq = NULL;
+
+ clk_disable(wdt_clock);
+ clk_put(wdt_clock);
+ wdt_clock = NULL;
iounmap(wdt_base);
misc_deregister(&s3c2410wdt_miscdev);
[-- Attachment #2: 2620-rc1-s3c24xx-watchdog-balance.patch --]
[-- Type: text/x-diff, Size: 2732 bytes --]
diff -urpN -X ../dontdiff linux-2.6.20-rc1/drivers/char/watchdog/s3c2410_wdt.c linux-2.6.20-rc1-fix2/drivers/char/watchdog/s3c2410_wdt.c
--- linux-2.6.20-rc1/drivers/char/watchdog/s3c2410_wdt.c 2006-11-29 21:57:37.000000000 +0000
+++ linux-2.6.20-rc1-fix2/drivers/char/watchdog/s3c2410_wdt.c 2006-12-18 10:26:55.000000000 +0000
@@ -366,13 +366,15 @@ static int s3c2410wdt_probe(struct platf
wdt_mem = request_mem_region(res->start, size, pdev->name);
if (wdt_mem == NULL) {
printk(KERN_INFO PFX "failed to get memory region\n");
- return -ENOENT;
+ ret = -ENOENT;
+ goto err_req;
}
wdt_base = ioremap(res->start, size);
if (wdt_base == 0) {
printk(KERN_INFO PFX "failed to ioremap() region\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_req;
}
DBG("probe: mapped wdt_base=%p\n", wdt_base);
@@ -380,22 +382,21 @@ static int s3c2410wdt_probe(struct platf
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (res == NULL) {
printk(KERN_INFO PFX "failed to get irq resource\n");
- iounmap(wdt_base);
- return -ENOENT;
+ ret = -ENOENT;
+ goto err_map;
}
ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, pdev);
if (ret != 0) {
printk(KERN_INFO PFX "failed to install irq (%d)\n", ret);
- iounmap(wdt_base);
- return ret;
+ goto err_map;
}
wdt_clock = clk_get(&pdev->dev, "watchdog");
if (wdt_clock == NULL) {
printk(KERN_INFO PFX "failed to find watchdog clock source\n");
- iounmap(wdt_base);
- return -ENOENT;
+ ret = -ENOENT;
+ goto err_irq;
}
clk_enable(wdt_clock);
@@ -418,8 +419,7 @@ static int s3c2410wdt_probe(struct platf
if (ret) {
printk (KERN_ERR PFX "cannot register miscdev on minor=%d (%d)\n",
WATCHDOG_MINOR, ret);
- iounmap(wdt_base);
- return ret;
+ goto err_clk;
}
if (tmr_atboot && started == 0) {
@@ -434,26 +434,36 @@ static int s3c2410wdt_probe(struct platf
}
return 0;
+
+ err_clk:
+ clk_disable(wdt_clock);
+ clk_put(wdt_clock);
+
+ err_irq:
+ free_irq(wdt_irq->start, pdev);
+
+ err_map:
+ iounmap(wdt_base);
+
+ err_req:
+ release_resource(wdt_mem);
+ kfree(wdt_mem);
+
+ return ret;
}
static int s3c2410wdt_remove(struct platform_device *dev)
{
- if (wdt_mem != NULL) {
- release_resource(wdt_mem);
- kfree(wdt_mem);
- wdt_mem = NULL;
- }
-
- if (wdt_irq != NULL) {
- free_irq(wdt_irq->start, dev);
- wdt_irq = NULL;
- }
-
- if (wdt_clock != NULL) {
- clk_disable(wdt_clock);
- clk_put(wdt_clock);
- wdt_clock = NULL;
- }
+ release_resource(wdt_mem);
+ kfree(wdt_mem);
+ wdt_mem = NULL;
+
+ free_irq(wdt_irq->start, dev);
+ wdt_irq = NULL;
+
+ clk_disable(wdt_clock);
+ clk_put(wdt_clock);
+ wdt_clock = NULL;
iounmap(wdt_base);
misc_deregister(&s3c2410wdt_miscdev);
next reply other threads:[~2006-12-18 10:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-18 10:31 Ben Dooks [this message]
2006-12-19 21:18 ` Wim Van Sebroeck
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=20061218103132.GA10691@home.fluff.org \
--to=ben-linux@fluff.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wim@iguana.be \
/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
all inboxes | Powered by JetHome®