Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oleksij Rempel" <o.rempel@pengutronix.de>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
	linux-hwmon@vger.kernel.org, krzk+dt@kernel.org
Subject: Re: [PATCH v12 2/6] mfd: add NXP MC33978/MC34978 core driver
Date: Fri, 15 May 2026 16:48:51 +0000	[thread overview]
Message-ID: <20260515164852.6848BC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260515160537.115808-3-o.rempel@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Sustained hardware faults cause a 100% CPU lockup in the event handling loop.
- [Medium] Transient fault detection logic is dead code due to pipelined SPI dummy fetch filtering.
--

commit a9e570c4deed793a38c78aa7e88c2bfc68e7b1cd
Author: Oleksij Rempel <o.rempel@pengutronix.de>

    mfd: add NXP MC33978/MC34978 core driver

Add core Multi-Function Device (MFD) driver for the NXP MC33978 and MC34978
Multiple Switch Detection Interfaces (MSDI).

> diff --git a/drivers/platform/misc/mc33978-core.c b/drivers/platform/misc/mc33978-core.c
> index 0000000000000..287b524aed98a
> --- /dev/null
> +++ b/drivers/platform/misc/mc33978-core.c

[ ... ]

> 	/*
> 	 * Transient fault detection (§9.10.27): FAULT_STAT latches on fault
> 	 * occurrence and persists until Fault register (0x42) read clears it.
> 	 * Hwmon driver reads Fault register, which triggers regmap SPI read with
> 	 * pipelined frames: REQ frame (old response, FAULT_STAT=1 latched) and
> 	 * PIPE frame (Fault register response clears latch). If fault condition
> 	 * cleared between latch and read, FAULT_STAT won't re-latch (datasheet:
> 	 * "immediately set again if condition still present").
> 	 *
> 	 * Transient detection: hw_flags contains harvested FAULT_STAT bit
> 	 * (latched evidence from REQ frame), but bus_fault_active=0 and
> 	 * cached_fault_active=0 (PIPE frame showed cleared, condition gone).
> 	 * This proves brief fault (VBATP voltage glitch, threshold oscillation)
> 	 * occurred and cleared before Fault register read. Edge-triggered
> 	 * consumers need this event notification.
> 	 *
> 	 * WAKE_BIT exclusion: WAKE_BIT is synthetic (bus_fault_active changes),
> 	 * not hardware evidence. Including it causes phantom transients when
> 	 * normal faults deassert (WAKE_BIT present but no actual transient).
> 	 */
> 	transient = !changed && !fault_active && !cached_fault &&
> 		    (hw_flags & MC33978_HI_BYTE_STAT_FAULT);

Is it possible that the transient fault detection logic is never executed?

Since mc33978_prepare_messages() hardcodes the dummy fetch for the PIPE frame
to be MC33978_REG_CHECK, the REQ frame in the next SPI read will contain the
response to REG_CHECK.

However, mc33978_rx_decode() explicitly sets has_status = false for
MC33978_REG_CHECK and returns -ENODATA.

This skips status harvesting for the REQ frame in mc33978_spi_read(), meaning
the latched FAULT_STAT evidence might never be harvested.

[ ... ]

> static void mc33978_process_single_event(struct mc33978_core_data *cdata)
> {
> 	unsigned int harvested;
> 	unsigned int pin_state;
> 	int ret;
> 
> 	/*
> 	 * Grab harvested_flags BEFORE hardware read. Flags harvested during
> 	 * the read trigger another loop pass. This intentionally forces a
> 	 * redundant SPI read on most interrupts, but is necessary to prevent
> 	 * lost events when concurrent regmap access races with IRQ thread
> 	 * (hardware has clear-on-read INT_flg).
> 	 */
> 	harvested = atomic_xchg(&cdata->harvested_flags, 0);
> 
> 	ret = regmap_read(cdata->map, MC33978_REG_READ_IN, &pin_state);
> 	if (ret)
> 		dev_err_ratelimited(&cdata->spi->dev, "failed to read pin state: %d\n",
> 				    ret);
> 	else
> 		mc33978_handle_pin_changes(cdata, pin_state);
> 
> 	mc33978_handle_fault_condition(cdata, harvested);
> }
> 
> static void mc33978_handle_events(struct mc33978_core_data *cdata)
> {
> 	guard(mutex)(&cdata->event_lock);
> 
> 	do {
> 		mc33978_process_single_event(cdata);
> 	} while (atomic_read(&cdata->harvested_flags) != 0);

Can a sustained hardware fault cause a soft lockup in this event loop?

If a persistent physical fault exists, the hardware continuously latches
FAULT_STAT=1. The regmap_read() to MC33978_REG_READ_IN inside
mc33978_process_single_event() triggers mc33978_spi_read(), which then
calls mc33978_harvest_status().

Because mc33978_harvest_status() unconditionally adds
MC33978_HI_BYTE_STAT_FAULT back into cdata->harvested_flags, the
atomic_read(&cdata->harvested_flags) check would perpetually evaluate
to true.

> }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260515160537.115808-1-o.rempel@pengutronix.de?part=2

  reply	other threads:[~2026-05-15 16:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 16:05 [PATCH v12 0/6] mfd: Add support for NXP MC33978/MC34978 MSDI Oleksij Rempel
2026-05-15 16:05 ` [PATCH v12 1/6] dt-bindings: pinctrl: add " Oleksij Rempel
2026-05-15 16:05 ` [PATCH v12 2/6] mfd: add NXP MC33978/MC34978 core driver Oleksij Rempel
2026-05-15 16:48   ` sashiko-bot [this message]
2026-05-15 16:05 ` [PATCH v12 3/6] pinctrl: core: Make pin group callbacks optional for pin-only drivers Oleksij Rempel
2026-05-15 17:43   ` sashiko-bot
2026-05-15 16:05 ` [PATCH v12 4/6] pinctrl: add NXP MC33978/MC34978 pinctrl driver Oleksij Rempel
2026-05-15 18:07   ` sashiko-bot
2026-05-15 16:05 ` [PATCH v12 5/6] hwmon: add NXP MC33978/MC34978 driver Oleksij Rempel
2026-05-15 18:38   ` sashiko-bot
2026-05-15 16:05 ` [PATCH v12 6/6] mux: add NXP MC33978/MC34978 AMUX driver Oleksij Rempel
2026-05-15 19:07   ` sashiko-bot

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=20260515164852.6848BC2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=robh@kernel.org \
    --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