From: sashiko-bot@kernel.org
To: "Sasha Finkelstein" <k@chaosmail.tech>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 2/6] spmi: apple: Validate FIFO state
Date: Wed, 05 Aug 2026 10:21:24 +0000 [thread overview]
Message-ID: <20260805102124.D21EB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805-t603x-spmi-v4-2-c15a12d9a7d1@chaosmail.tech>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] The FIFO flush command is written to the wrong register (`SPMI_RSP_REG` instead of `SPMI_ACT_REG`).
- [High] Missing `spmi->prev_fail = true` assignment when aborting due to an empty RX FIFO.
Pre-existing issues:
- [High] Bus transactions are not serialized, leading to potential race conditions on the FIFO and controller registers.
--
--- Patch [2]: [PATCH v4 2/6] spmi: apple: Validate FIFO state ---
commit 22dd698ab8c4900ee8f167f7c5d03df7bd152f3b
Author: Alba Mendez <me@alba.sh>
spmi: apple: Validate FIFO state
Check for data before reading the body of a reply, and check for
end of data afterwards.
> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> index 376cf682c43e0..4d5356bf9bbf1 100644
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
[ ... ]
> @@ -67,6 +71,11 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
[Severity: High]
This is a pre-existing issue, but since spmi_read_cmd() lacks a mutex or
spinlock, what prevents concurrent calls from different client drivers
(like regulators or RTC) from interleaving?
Without serialization, concurrent accesses to the controller registers could
corrupt the state or wedge the controller. This pre-existing issue also
affects the newly added prev_fail flag, which could be overwritten or
misread during interleaved bus operations.
> u8 i;
> int ret;
>
> + if (spmi->prev_fail) {
> + writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_RSP_REG);
[Severity: High]
Is it intended to write SPMI_ACT_FIFO_FLUSH to SPMI_RSP_REG?
It looks like this might have meant to write to the newly defined
SPMI_ACT_REG instead. Writing an action command to the response register
could leave the FIFO unflushed and leave the controller permanently wedged
after an error.
> + spmi->prev_fail = false;
> + }
> +
> writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
>
> ret = apple_spmi_wait_rx_not_empty(ctrl);
[ ... ]
> @@ -78,6 +87,11 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>
> /* Read SPMI data reply */
> while (len_read < len) {
> + if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
> + dev_err_ratelimited(&ctrl->dev,
> + "FIFO lacks reply data, controller stuck?\n");
> + return -EIO;
[Severity: High]
When the loop aborts here due to an empty RX FIFO, shouldn't spmi->prev_fail
be set to true before returning?
If the hardware response is slow and causes an early exit without setting
this flag, the next transaction will not flush the delayed reply. Could this
cause the subsequent transaction to read stale reply data as its own, leading
to silent data corruption for downstream PMIC clients?
> + }
> rsp = readl(spmi->regs + SPMI_RSP_REG);
> i = 0;
> while ((len_read < len) && (i < 4)) {
[ ... ]
> @@ -97,6 +116,11 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
[Severity: High]
This is a pre-existing issue, but similar to spmi_read_cmd(), the
spmi_write_cmd() function also lacks synchronization, leaving it vulnerable to
concurrent accesses from different SPMI bus clients.
> size_t i = 0, j;
> int ret;
>
> + if (spmi->prev_fail) {
> + writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_RSP_REG);
[Severity: High]
Does this also need to be written to SPMI_ACT_REG instead of SPMI_RSP_REG?
> + spmi->prev_fail = false;
> + }
> +
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-t603x-spmi-v4-0-c15a12d9a7d1@chaosmail.tech?part=2
next prev parent reply other threads:[~2026-08-05 10:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 10:11 [PATCH v4 0/6] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-08-05 10:11 ` [PATCH v4 1/6] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
2026-08-05 10:19 ` sashiko-bot
2026-08-05 12:01 ` Janne Grunau
2026-08-05 10:11 ` [PATCH v4 2/6] spmi: apple: Validate FIFO state Sasha Finkelstein
2026-08-05 10:21 ` sashiko-bot [this message]
2026-08-05 12:03 ` Janne Grunau
2026-08-05 10:11 ` [PATCH v4 3/6] spmi: apple: check transaction status Sasha Finkelstein
2026-08-05 10:27 ` sashiko-bot
2026-08-05 12:06 ` Janne Grunau
2026-08-05 10:11 ` [PATCH v4 4/6] spmi: apple: Implement remaining commands Sasha Finkelstein
2026-08-05 10:24 ` sashiko-bot
2026-08-05 12:19 ` Janne Grunau
2026-08-05 16:54 ` Sasha Finkelstein
2026-08-05 10:11 ` [PATCH v4 5/6] spmi: apple: lock around FIFOs Sasha Finkelstein
2026-08-05 10:25 ` sashiko-bot
2026-08-05 12:25 ` Janne Grunau
2026-08-05 10:11 ` [PATCH v4 6/6] spmi: apple: Add interrupt functionality Sasha Finkelstein
2026-08-05 10:22 ` sashiko-bot
2026-08-05 12:42 ` Janne Grunau
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=20260805102124.D21EB1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=k@chaosmail.tech \
--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