Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tomer Maimon" <tmaimon77@gmail.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org,
	linux-watchdog@vger.kernel.org
Subject: Re: [PATCH v3 3/3] watchdog: npcm: add bootstatus support
Date: Sun, 05 Jul 2026 14:10:48 +0000	[thread overview]
Message-ID: <20260705141048.75C5D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260705140100.1543486-4-tmaimon77@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [High] Non-atomic read-modify-write on shared syscon registers corrupts concurrent updates or incorrectly clears W1C bits.
- [High] The driver hijacks standardized watchdog bootstatus flags to report unrelated SoC reset reasons.
- [Low] The driver hardcodes physical MMIO base addresses to identify driver instances.

Pre-existing issues:
- [High] The driver leaks a clock enable reference on every timeout change and fails to clean up on probe errors.
--

commit 3d82c9ef067a4770a83258e13cbb0ed566d4998b
Author: Tomer Maimon <tmaimon77@gmail.com>

watchdog: npcm: add bootstatus support

The NPCM750 uses RESSR and the NPCM845 uses INTCR2 to latch reset indications.
Read those bits during probe and map them into watchdog bootstatus flags. For
NPCM845, cache the sampled INTCR2 state in SCRPAD10 after the reset status
bits are cleared.

> diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c
> index e62ea054bc618..82ff3956dcf21 100644
> --- a/drivers/watchdog/npcm_wdt.c
> +++ b/drivers/watchdog/npcm_wdt.c

[ ... ]

> +static const struct npcm_wdt_rst_map npcm750_rst_map[] = {
> +	{ 0xf000801c, NPCM_WD0RST },
> +	{ 0xf000901c, NPCM_WD1RST },
> +	{ 0xf000a01c, NPCM_WD2RST },
> +};

[Severity: Low]
Does this code hardcode physical MMIO base addresses to identify driver
instances?

Matching the resource start address against hardcoded values in
npcm_get_reset_status() can be brittle if the memory map changes in future
SoC revisions or alternative device tree mappings. Is there a way to use
device tree aliases or instance IDs to identify the hardware block instead?

> +
> +static const struct npcm_wdt_status_map npcm750_status_map[] = {
> +	{ NPCM_PORST, WDIOF_OVERHEAT },
> +	{ NPCM_CORST, WDIOF_FANFAULT },
> +	{ NPCM_SWR1RST, WDIOF_EXTERN1 },
> +	{ NPCM_SWR2RST, WDIOF_EXTERN2 },
> +	{ NPCM_SWR3RST, WDIOF_POWERUNDER },
> +	{ NPCM_SWR4RST, WDIOF_POWEROVER },
> +};

[Severity: High]
Does this mapping hijack standardized watchdog bootstatus flags to report
unrelated SoC reset reasons?

Translating NPCM SoC-specific reset reasons into standard UAPI flags might
cause issues in userspace. For example, WDIOF_OVERHEAT and WDIOF_FANFAULT
are strictly defined in the UAPI to indicate thermal overheating and fan
failures.

Could system monitoring tools misinterpret a normal cold boot (NPCM_CORST)
as a severe hardware failure and trigger unintended alerts or shutdowns?

[ ... ]

> +static void npcm_get_reset_status(struct npcm_wdt *wdt, struct device *dev,
> +				  const struct npcm_wdt_data *data,
> +				  resource_size_t start)
> +{

[ ... ]

> +	if (of_device_is_compatible(dev->of_node, "nuvoton,npcm845-wdt")) {
> +		ret = regmap_read(gcr_regmap, NPCM_INTCR2_OFFSET, &rstval);
> +		if (ret) {
> +			dev_warn(dev, "Failed to read INTCR2 reset status: %d\n",
> +				 ret);
> +			return;
> +		}
> +
> +		if (rstval & NPCM_RST) {
> +			ret = regmap_write(gcr_regmap, NPCM_INTCR2_OFFSET,
> +					   rstval & ~NPCM_RST);

[Severity: High]
Can this non-atomic read-modify-write sequence on the shared syscon
register corrupt concurrent updates?

If INTCR2 (and RESSR below) are standard read-write registers, this
sequence could silently overwrite modifications made by other drivers
sharing the syscon.

Alternatively, if these are Write-1-to-Clear (W1C) registers, writing
rstval & ~NPCM_RST will write 1s to all other active status bits,
inadvertently clearing them, while writing 0 to the watchdog bits,
failing to clear the intended reset flags.

Would it be safer to use regmap_update_bits() for atomic updates, or if
W1C, write only the target bits without a read-modify-write?

[ ... ]

> @@ -220,6 +430,8 @@ static int npcm_wdt_probe(struct platform_device *pdev)
>  	/* Ensure timeout is able to be represented by the hardware */
>  	npcm_wdt_set_timeout(&wdt->wdd, wdt->wdd.timeout);
>  
> +	npcm_get_reset_status(wdt, dev, data, start);
> +
>  	if (npcm_is_running(&wdt->wdd)) {
>  		/* Restart with the default or device-tree specified timeout */
>  		npcm_wdt_start(&wdt->wdd);
>  		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
>  	}
>  
>  	ret = devm_request_irq(dev, irq, npcm_wdt_interrupt, 0, "watchdog",
>  			       wdt);
>  	if (ret)
>  		return ret;

[Severity: High]
This is a pre-existing issue, but does this code leak a clock enable
reference?

In npcm_wdt_probe(), if the hardware is running, npcm_wdt_start() is called:

npcm_wdt_start()
    clk_prepare_enable(wdt->clk);

If subsequent probe steps fail (e.g., devm_request_irq() returns an error),
probe returns without unwinding the clock enable.

Additionally, npcm_wdt_set_timeout() calls npcm_wdt_start() when the watchdog
is active. Since there is no matching disable on timeout change, every
WDIOC_SETTIMEOUT ioctl increments the clock's refcount. This prevents
the clock from ever being disabled when the watchdog is stopped, leading
to a resource leak.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260705140100.1543486-1-tmaimon77@gmail.com?part=3

  reply	other threads:[~2026-07-05 14:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-05 14:00 [PATCH v3 0/3] watchdog: npcm: Add reset status detection support Tomer Maimon
2026-07-05 14:00 ` [PATCH v3 1/3] dt-bindings: watchdog: npcm: add GCR syscon property Tomer Maimon
2026-07-05 14:36   ` Conor Dooley
2026-07-05 14:00 ` [PATCH v3 2/3] docs: watchdog: npcm: Add reset status description Tomer Maimon
2026-07-05 14:06   ` sashiko-bot
2026-07-06  9:44     ` Tomer Maimon
2026-07-05 14:01 ` [PATCH v3 3/3] watchdog: npcm: add bootstatus support Tomer Maimon
2026-07-05 14:10   ` sashiko-bot [this message]
2026-07-06 14:47     ` Tomer Maimon

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=20260705141048.75C5D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tmaimon77@gmail.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