From: Tzung-Bi Shih <tzungbi@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: Wanming Gao <wanming.gao@mediatek.com>, linux-watchdog@vger.kernel.org
Subject: Re: [PATCH] watchdog: mediatek: Enable pretimeout support
Date: Wed, 26 Aug 2026 04:36:36 +0000 [thread overview]
Message-ID: <ao5tVCpb1pMu14Tb@google.com> (raw)
In-Reply-To: <20260824133823.884931F000E9@smtp.kernel.org>
On Mon, Aug 24, 2026 at 01:38:23PM +0000, sashiko-bot@kernel.org wrote:
> > @@ -230,14 +230,17 @@ static int mtk_wdt_restart(struct watchdog_device *wdt_dev,
> > {
> > struct mtk_wdt_dev *mtk_wdt = watchdog_get_drvdata(wdt_dev);
> > void __iomem *wdt_base;
> > + unsigned long flags;
> > u32 reg;
> >
> > wdt_base = mtk_wdt->wdt_base;
> >
> > /* Enable reset in order to issue a system reset instead of an IRQ */
> > + spin_lock_irqsave(&mtk_wdt->lock, flags);
>
> [Severity: High]
> Does acquiring this spinlock unconditionally risk a deadlock during a system
> panic?
>
> The restart handler is called during emergency restarts. If another CPU was
> stopped via an IPI while holding mtk_wdt->lock (such as during the 70
> microsecond delay in mtk_wdt_deassert_irq()), the panicking CPU will spin
> infinitely here and hang the emergency reboot.
The .restart() callback can be called during a normal reboot or an emergency
restart. In either case, local interrupts are disabled and there should be
no other concurrent CPU running this piece of code. The lock acquisition is
unnecessary here and can be safely dropped to avoid the deadlock risk.
> > +static void mtk_wdt_deassert_irq(struct watchdog_device *wdd)
> > +{
> > + struct mtk_wdt_dev *mtk_wdt = watchdog_get_drvdata(wdd);
>
> [Severity: High]
> Will watchdog_get_drvdata() return NULL here if a pending interrupt fires
> during probe?
>
> In mtk_wdt_probe(), devm_request_irq() is called to enable the interrupt before
> watchdog_set_drvdata() initializes the driver data. If the bootloader left the
> pretimeout interrupt enabled and it fires immediately during probe,
> mtk_wdt_isr() will run and call mtk_wdt_deassert_irq().
>
> This would result in watchdog_get_drvdata() returning NULL, followed by a NULL
> pointer dereference when accessing mtk_wdt->wdt_base.
To prevent the race condition, it would be safer to use IRQF_NO_AUTOEN when
calling request_irq() and call enable_irq() when the driver is fully ready.
next prev parent reply other threads:[~2026-08-26 4:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 13:29 [PATCH] watchdog: mediatek: Enable pretimeout support Wanming Gao
2026-08-24 13:38 ` sashiko-bot
2026-08-26 4:36 ` Tzung-Bi Shih [this message]
2026-08-26 4:36 ` Tzung-Bi Shih
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=ao5tVCpb1pMu14Tb@google.com \
--to=tzungbi@kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wanming.gao@mediatek.com \
/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