mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: linux-watchdog@vger.kernel.org
Cc: Wim Van Sebroeck <wim@iguana.be>,
	linux-kernel@vger.kernel.org, Ian Abbott <abbotti@mev.co.uk>
Subject: [PATCH 2/5] watchdog: dw_wdt: reject additional device probes
Date: Fri, 26 Jun 2015 14:21:10 +0100	[thread overview]
Message-ID: <1435324873-18318-3-git-send-email-abbotti@mev.co.uk> (raw)
In-Reply-To: <1435324873-18318-1-git-send-email-abbotti@mev.co.uk>

Certain Altera FPGAs have an ARM-based Hard Processor System (HPS) that
includes two DesignWare Watchdog Timer peripherals.  Problems occur if
both are enabled in the device tree as the "dw_wdt" driver only supports
a single device, using a static variable (`dw_wdt`) to hold its state.
Typically, the timer queue gets corrupted, leading to a kernel Oops.

Use bit 1 of `dw_wdt.state` to indicate that a device has already been
probed, and reject attempts to probe extra devices.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/watchdog/dw_wdt.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index 249ef09..cece633 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -61,6 +61,7 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
 
 /* dw_wdt.state bit numbers */
 #define DW_WDT_IN_USE		0
+#define DW_WDT_PROBED		1
 
 static struct {
 	void __iomem		*regs;
@@ -335,17 +336,26 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 	int ret;
 	struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
+	if (test_and_set_bit(DW_WDT_PROBED, &dw_wdt.state)) {
+		pr_err("This driver only supports one device\n");
+		return -ENODEV;
+	}
+
 	dw_wdt.regs = devm_ioremap_resource(&pdev->dev, mem);
-	if (IS_ERR(dw_wdt.regs))
-		return PTR_ERR(dw_wdt.regs);
+	if (IS_ERR(dw_wdt.regs)) {
+		ret = PTR_ERR(dw_wdt.regs);
+		goto out_unmark_probed;
+	}
 
 	dw_wdt.clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(dw_wdt.clk))
-		return PTR_ERR(dw_wdt.clk);
+	if (IS_ERR(dw_wdt.clk)) {
+		ret = PTR_ERR(dw_wdt.clk);
+		goto out_unmark_probed;
+	}
 
 	ret = clk_prepare_enable(dw_wdt.clk);
 	if (ret)
-		return ret;
+		goto out_unmark_probed;
 
 	ret = misc_register(&dw_wdt_miscdev);
 	if (ret)
@@ -366,6 +376,9 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 out_disable_clk:
 	clk_disable_unprepare(dw_wdt.clk);
 
+out_unmark_probed:
+	clear_bit(DW_WDT_PROBED, &dw_wdt.state);
+
 	return ret;
 }
 
@@ -377,6 +390,8 @@ static int dw_wdt_drv_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(dw_wdt.clk);
 
+	clear_bit(DW_WDT_PROBED, &dw_wdt.state);
+
 	return 0;
 }
 
-- 
2.1.4


  parent reply	other threads:[~2015-06-26 13:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 13:21 [PATCH 0/5] watchdog: dw_wdt: allow only one probe + various fixes Ian Abbott
2015-06-26 13:21 ` [PATCH 1/5] watchdog: dw_wdt: prepare for more atomic bits Ian Abbott
2015-06-26 13:21 ` Ian Abbott [this message]
2015-06-26 13:21 ` [PATCH 3/5] watchdog: dw_wdt: only unregister restart handler if registered Ian Abbott
2015-06-26 13:21 ` [PATCH 4/5] watchdog: dw_wdt: unqueue timer on device removal Ian Abbott
2015-06-26 13:21 ` [PATCH 5/5] watchdog: dw_wdt: unqueue timer synchronously on unexpected close Ian Abbott
2015-06-26 13:54 ` [PATCH 0/5] watchdog: dw_wdt: allow only one probe + various fixes Guenter Roeck

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=1435324873-18318-3-git-send-email-abbotti@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@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®