Linux Watchdog driver development
 help / color / mirror / Atom feed
From: Konstantin Khlebnikov <khlebnikov@openvz.org>
To: linux-kernel@vger.kernel.org
Cc: Wim Van Sebroeck <wim@iguana.be>,
	linux-watchdog@vger.kernel.org,
	Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH] drivers/watchdog/eurotechwdt: handle spurious interrupts on wrong hardware
Date: Tue, 18 Dec 2012 14:00:23 +0400	[thread overview]
Message-ID: <20121218100023.26480.13240.stgit@zurg> (raw)

"eurotechwdt" hasn't any PCI-ID or DMI checks, thus is can be loaded on any
hardware. On my PC this leads to immediate reboot, because driver got irq right
after registering irq handler. This patch rejects interrupts until device
activation. There is no sense to load this driver without special hardware,
but such bugs blocks mine automatic testing for allmodconfig kernels.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Wim Van Sebroeck <wim@iguana.be>
Cc: linux-watchdog@vger.kernel.org
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>

---

by default driver uses 10th irq, on my machine it's free:

root@buzz:~# cat /proc/interrupts
           CPU0       CPU1
  0:        187          0   IO-APIC-edge      timer
  1:          0          8   IO-APIC-edge      i8042
  7:          2          0   IO-APIC-edge      parport0
  8:          0          1   IO-APIC-edge      rtc0
  9:          0          0   IO-APIC-fasteoi   acpi
 10:          1          0   IO-APIC-edge
 14:          1         61   IO-APIC-edge      pata_amd
 15:          0          0   IO-APIC-edge      pata_amd
 20:          0        317   IO-APIC-fasteoi   snd_hda_intel
 22:          0          2   IO-APIC-fasteoi   ehci_hcd:usb1, sata_nv
 23:          6       3667   IO-APIC-fasteoi   ohci_hcd:usb2, sata_nv
 41:         93     776888   PCI-MSI-edge      eth0
NMI:          0          2   Non-maskable interrupts
LOC:      13293      32610   Local timer interrupts
SPU:          0          0   Spurious interrupts
PMI:          0          2   Performance monitoring interrupts
IWI:          0          0   IRQ work interrupts
RTR:          0          0   APIC ICR read retries
RES:      11427       7619   Rescheduling interrupts
CAL:        182         52   Function call interrupts
TLB:        824        580   TLB shootdowns
TRM:          0          0   Thermal event interrupts
THR:          0          0   Threshold APIC interrupts
MCE:          0          0   Machine check exceptions
MCP:          2          2   Machine check polls
ERR:          1
MIS:          0
---
 drivers/watchdog/eurotechwdt.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/watchdog/eurotechwdt.c b/drivers/watchdog/eurotechwdt.c
index cd31b8a..7d24914 100644
--- a/drivers/watchdog/eurotechwdt.c
+++ b/drivers/watchdog/eurotechwdt.c
@@ -65,6 +65,7 @@
 static unsigned long eurwdt_is_open;
 static int eurwdt_timeout;
 static char eur_expect_close;
+static bool eurwdt_is_active;
 static DEFINE_SPINLOCK(eurwdt_lock);
 
 /*
@@ -139,6 +140,7 @@ static inline void eurwdt_disable_timer(void)
 static void eurwdt_activate_timer(void)
 {
 	eurwdt_disable_timer();
+	eurwdt_is_active = true;
 	eurwdt_write_reg(WDT_CTRL_REG, 0x01);	/* activate the WDT */
 	eurwdt_write_reg(WDT_OUTPIN_CFG,
 		!strcmp("int", ev) ? WDT_EVENT_INT : WDT_EVENT_REBOOT);
@@ -164,6 +166,11 @@ static void eurwdt_activate_timer(void)
 
 static irqreturn_t eurwdt_interrupt(int irq, void *dev_id)
 {
+	if (!eurwdt_is_active) {
+		pr_crit("spurious interrupt\n");
+		return IRQ_NONE;
+	}
+
 	pr_crit("timeout WDT timeout\n");
 
 #ifdef ONLY_TESTING

             reply	other threads:[~2012-12-18 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-18 10:00 Konstantin Khlebnikov [this message]
2012-12-19 15:48 ` [PATCH] drivers/watchdog/eurotechwdt: handle spurious interrupts on wrong hardware Konstantin Khlebnikov

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=20121218100023.26480.13240.stgit@zurg \
    --to=khlebnikov@openvz.org \
    --cc=alan@lxorguk.ukuu.org.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