From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [PATCH 2/2] watchdog: sama5d4: use platform_get_irq_optional()
Date: Thu, 04 Jun 2026 01:13:35 +0000 [thread overview]
Message-ID: <20260604011335.C6DEF1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604010542.23177-3-rosenp@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Race condition leading to NULL pointer dereference if the watchdog interrupt fires before probe completes.
--
commit 81aa11d20f236c5efcd53479d7c7d1601cbc92d0
Author: Rosen Penev <rosenp@gmail.com>
watchdog: sama5d4: use platform_get_irq_optional()
irq_of_parse_and_map() requires irq_dispose_mapping() on failure. Don't
bother with it as platform_get_irq_optional() doesn't need it.
Also handle EPROBE_DEFER.
> diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c
> index b7b5b24afb34b..d218fc04b770c 100644
> --- a/drivers/watchdog/sama5d4_wdt.c
> +++ b/drivers/watchdog/sama5d4_wdt.c
[ ... ]
> @@ -287,8 +286,11 @@ static int sama5d4_wdt_probe(struct platform_device *pdev)
> return ret;
>
> if (wdt->need_irq) {
> - irq = irq_of_parse_and_map(dev->of_node, 0);
> - if (!irq) {
> + irq = platform_get_irq_optional(pdev, 0);
> + if (irq == -EPROBE_DEFER)
> + return irq;
> +
> + if (irq < 0) {
> dev_warn(dev, "failed to get IRQ from DT\n");
> wdt->need_irq = false;
> }
[Severity: High]
This is a pre-existing issue, but since the IRQ handling is being updated
here, could this lead to a NULL pointer dereference if the interrupt fires
early?
Further down in sama5d4_wdt_probe(), the interrupt is registered and
unmasked, passing pdev as the dev_id context:
drivers/watchdog/sama5d4_wdt.c:sama5d4_wdt_probe() {
...
ret = devm_request_irq(dev, irq, sama5d4_wdt_irq_handler,
IRQF_IRQPOLL | IRQF_NO_SUSPEND,
pdev->name, pdev);
...
ret = sama5d4_wdt_init(wdt, wdd->timeout);
...
}
The sama5d4_wdt_init() function enables the hardware interrupts, creating
a race window because platform_set_drvdata(pdev, wdt) is not called until
the very end of the probe function.
If an interrupt fires before platform_set_drvdata() completes (for example,
if left pending by the bootloader), the interrupt handler will retrieve a NULL
pointer:
drivers/watchdog/sama5d4_wdt.c:sama5d4_wdt_irq_handler() {
struct sama5d4_wdt *wdt = platform_get_drvdata(dev_id);
...
if (wdt->sam9x60_support)
...
}
Should platform_set_drvdata() be moved up before the interrupt is
requested, or should devm_request_irq() be passed the wdt pointer directly
instead of pdev?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604010542.23177-1-rosenp@gmail.com?part=2
prev parent reply other threads:[~2026-06-04 1:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 1:05 [PATCH 0/2] watchdog: sama5d4: fix IRQ and timeout bugs, use platform_get_irq_optional Rosen Penev
2026-06-04 1:05 ` [PATCH 1/2] watchdog: sama5d4: fix shared IRQ and hardcoded timeout issues Rosen Penev
2026-06-04 1:20 ` sashiko-bot
2026-06-04 1:05 ` [PATCH 2/2] watchdog: sama5d4: use platform_get_irq_optional() Rosen Penev
2026-06-04 1:13 ` sashiko-bot [this message]
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=20260604011335.C6DEF1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=rosenp@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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