devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Finkelstein" <k@chaosmail.tech>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v7 2/6] spmi: apple: Validate FIFO state
Date: Tue, 18 Aug 2026 18:44:49 +0000	[thread overview]
Message-ID: <20260818184450.3AE931F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260818-t603x-spmi-v7-2-dafebe6e7739@chaosmail.tech>

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

New issues:
- [Medium] Instantaneous check of RX_FIFO_EMPTY randomly aborts valid multi-word reads if the hardware streams data.

Pre-existing issues:
- [High] Missing controller-level lock allows concurrent operations to corrupt SPMI bus transactions and race on prev_fail.
--

--- Patch [2]: [PATCH v7 2/6] spmi: apple: Validate FIFO state ---
commit b638b8c461a5028b5eb344197adecba7ccd922ba
Author: Alba Mendez <me@alba.sh>

spmi: apple: Validate FIFO state

This commit adds checks to validate the FIFO state before reading reply data
and after a command completes. It introduces a prev_fail flag and flushes
the FIFO before executing new commands if previous operations failed.

> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> --- 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,
>  	u8 i;
>  	int ret;
>  
> +	if (spmi->prev_fail) {

[Severity: High]
This isn't a bug introduced by this patch, but does this missing
controller-level lock allow concurrent operations to corrupt SPMI bus
transactions?

Since the SPMI subsystem exposes this controller to all its children and
does not natively serialize read_cmd or write_cmd operations, multiple
threads could invoke spmi_read_cmd() simultaneously. This would lead to
concurrent modifications of spmi->prev_fail and shared hardware registers
without mutual exclusion.

> +		writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG);
> +		spmi->prev_fail = false;
> +	}
> +
>  	writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);

[ ... ]

> @@ -78,6 +87,12 @@ 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) {
> +			spmi->prev_fail = true;
> +			dev_err_ratelimited(&ctrl->dev,
> +					    "FIFO lacks reply data, controller stuck?\n");
> +			return -EIO;
> +		}

[Severity: Medium]
Could this instantaneous check of SPMI_RX_FIFO_EMPTY spuriously abort valid
multi-word reads?

In a multi-word read transaction, the CPU might outrun the SPMI bus after
reading the first word. If the hardware streams data and hasn't buffered
the next word yet, the CPU will immediately see SPMI_RX_FIFO_EMPTY and
return -EIO instead of waiting for the next word to arrive.

>  		rsp = readl(spmi->regs + SPMI_RSP_REG);
>  		i = 0;

[ ... ]

> @@ -97,6 +117,11 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>  	size_t i = 0, j;
>  	int ret;
>  
> +	if (spmi->prev_fail) {

[Severity: High]
This is a pre-existing issue, but can concurrent calls to spmi_write_cmd()
race on spmi->prev_fail and hardware state?

Similar to spmi_read_cmd(), this modifies shared hardware state and
spmi->prev_fail without serialization.

> +		writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG);
> +		spmi->prev_fail = false;
> +	}
> +
>  	writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260818-t603x-spmi-v7-0-dafebe6e7739@chaosmail.tech?part=2

  reply	other threads:[~2026-08-18 18:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 18:32 [PATCH v7 0/6] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-08-18 18:32 ` [PATCH v7 1/6] dt-bindings: spmi: apple,spmi: Add t603x and t8122 Sasha Finkelstein
2026-08-18 18:32 ` [PATCH v7 2/6] spmi: apple: Validate FIFO state Sasha Finkelstein
2026-08-18 18:44   ` sashiko-bot [this message]
2026-08-18 18:32 ` [PATCH v7 3/6] spmi: apple: check transaction status Sasha Finkelstein
2026-08-18 18:46   ` sashiko-bot
2026-08-18 18:32 ` [PATCH v7 4/6] spmi: apple: Implement remaining commands Sasha Finkelstein
2026-08-18 18:44   ` sashiko-bot
2026-08-18 18:32 ` [PATCH v7 5/6] spmi: apple: lock around FIFOs Sasha Finkelstein
2026-08-18 18:32 ` [PATCH v7 6/6] spmi: apple: Add interrupt functionality Sasha Finkelstein
2026-08-18 18:46   ` 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=20260818184450.3AE931F00A3E@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;
as well as URLs for NNTP newsgroup(s).