All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Finkelstein" <k@chaosmail.tech>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v9 4/6] spmi: apple: Implement remaining commands
Date: Tue, 01 Sep 2026 10:40:15 +0000	[thread overview]
Message-ID: <20260901104015.543841F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260901-t603x-spmi-v9-4-09e702e3b153@chaosmail.tech>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Endianness bug in `spmi_raw_cmd` due to improper mixing of `memcpy()` and `writel()`/`readl()` for FIFO stream accesses.
--

commit cb6fc258a7a80697550d0e3d62f761cda4b89087
Author: Alba Mendez <me@alba.sh>

spmi: apple: Implement remaining commands
    
Add support for zero write and power management commands.

> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> index b1c127cf5f441..9843dc871d6c7 100644
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
[ ... ]
> @@ -86,6 +85,14 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>  
>  	writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
>  
> +	while (i < len_wr) {
> +		j = min_t(size_t, sizeof(spmi_cmd), len_wr - i);
> +		spmi_cmd = 0;
> +		memcpy(&spmi_cmd, buf_wr + i, j);
> +		writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);

[Severity: Medium]
Will using memcpy() to write into a u32 followed by writel() cause an
endianness regression on big-endian systems?

On big-endian systems, memcpy() places the first byte at the most
significant byte of the u32. writel() then applies a byte-swap, placing
that first byte at the highest bus address (byte 3) instead of byte 0,
which would corrupt the data stream going into the FIFO.

The pre-patch code avoided this by using bitwise shifts to pack the u32
in a CPU-endian-independent manner. Mixing memcpy() and writel() violates
subsystem rules for FIFO I/O accessors.

> +		i += j;
> +	}
> +
>  	ret = apple_spmi_wait_rx_not_empty(ctrl);
>  	if (ret)
>  		return ret;
[ ... ]
> @@ -101,11 +109,9 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>  			return -EIO;
>  		}
>  		rsp = readl(spmi->regs + SPMI_RSP_REG);
> -		i = 0;
> -		while ((len_read < len) && (i < 4)) {
> -			buf[len_read++] = ((0xff << (8 * i)) & rsp) >> (8 * i);
> -			i += 1;
> -		}
> +		j = min_t(size_t, sizeof(spmi_cmd), len_rd - i);
> +		memcpy(buf_rd + i, &rsp, j);

[Severity: Medium]
Can this readl() followed by memcpy() cause the inverse data corruption on
the read path?

Like the write path, readl() performs a byte swap on big-endian systems,
meaning the memcpy() will extract the stream bytes in reverse order,
corrupting the responses received from the FIFO.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901-t603x-spmi-v9-0-09e702e3b153@chaosmail.tech?part=4

  reply	other threads:[~2026-09-01 10:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 10:28 [PATCH v9 0/6] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-09-01 10:29 ` [PATCH v9 1/6] dt-bindings: spmi: apple,spmi: Add t603x and t8122 Sasha Finkelstein
2026-09-01 10:39   ` sashiko-bot
2026-09-01 17:41   ` Conor Dooley
2026-09-01 18:24     ` Sasha Finkelstein
2026-09-02 17:02       ` Conor Dooley
2026-09-01 10:29 ` [PATCH v9 2/6] spmi: apple: Validate FIFO state Sasha Finkelstein
2026-09-01 10:29 ` [PATCH v9 3/6] spmi: apple: check transaction status Sasha Finkelstein
2026-09-01 10:29 ` [PATCH v9 4/6] spmi: apple: Implement remaining commands Sasha Finkelstein
2026-09-01 10:40   ` sashiko-bot [this message]
2026-09-01 10:29 ` [PATCH v9 5/6] spmi: apple: lock around FIFOs Sasha Finkelstein
2026-09-01 10:29 ` [PATCH v9 6/6] spmi: apple: Add interrupt functionality Sasha Finkelstein
2026-09-01 10:40   ` 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=20260901104015.543841F00A3D@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.