Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Finkelstein" <k@chaosmail.tech>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v10 4/6] spmi: apple: Implement remaining commands
Date: Fri, 02 Oct 2026 09:13:45 +0000	[thread overview]
Message-ID: <20261002091345.D57341F0089A@smtp.kernel.org> (raw)
In-Reply-To: <20261001-t603x-spmi-v10-4-ff815c66c73f@chaosmail.tech>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] spmi: apple: endianness regression via memcpy of IO registers
--

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

spmi: apple: Implement remaining commands

This commit adds support for zero write and power management commands to
the Apple SPMI controller driver.

> 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]
Does this cause an endianness regression on Big Endian architectures?

Using memcpy() to copy a u8 array into a u32 variable before passing it
to writel() can reverse the byte order. On Big Endian hosts, the first
byte of the array is placed in the most significant byte of the u32 in
memory, which writel() will then implicitly swap to Little Endian for
the bus, effectively reversing the byte stream.

While Apple SoCs currently operate in Little Endian, does this break
driver endianness-cleanliness and architectural portability?

> +		i += j;
> +	}
> +
>  	ret = apple_spmi_wait_rx_not_empty(ctrl);

[ ... ]

> @@ -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]
Similarly, does destructuring the readl() return value via memcpy() misplace
the bytes on Big Endian hosts?

The original code used bitwise operations to safely pack and unpack the
u32 words byte-by-byte, which inherently abstracts away host endianness.

> +		i += j;
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech?part=4

  reply	other threads:[~2026-10-02  9:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 20:26 [PATCH v10 0/6] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-10-01 20:26 ` [PATCH v10 1/6] dt-bindings: spmi: apple,spmi: Add t603x and t8122 Sasha Finkelstein
2026-10-02  9:13   ` sashiko-bot
2026-10-01 20:26 ` [PATCH v10 2/6] spmi: apple: Validate FIFO state Sasha Finkelstein
2026-10-01 20:26 ` [PATCH v10 3/6] spmi: apple: check transaction status Sasha Finkelstein
2026-10-01 20:26 ` [PATCH v10 4/6] spmi: apple: Implement remaining commands Sasha Finkelstein
2026-10-02  9:13   ` sashiko-bot [this message]
2026-10-01 20:27 ` [PATCH v10 5/6] spmi: apple: lock around FIFOs Sasha Finkelstein
2026-10-02  9:13   ` sashiko-bot
2026-10-01 20:27 ` [PATCH v10 6/6] spmi: apple: Add interrupt functionality Sasha Finkelstein
2026-10-02  9:13   ` 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=20261002091345.D57341F0089A@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