From: Janne Grunau <j@jannau.net>
To: Sasha Finkelstein <k@chaosmail.tech>
Cc: Sven Peter <sven@kernel.org>, Neal Gompa <neal@gompa.dev>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
Alba Mendez <me@alba.sh>
Subject: Re: [PATCH v2 5/7] spmi: apple: lock around FIFOs
Date: Sun, 2 Aug 2026 13:27:00 +0200 [thread overview]
Message-ID: <20260802112700.GG806854@robin.jannau.net> (raw)
In-Reply-To: <20260728-t603x-spmi-v2-5-f43e5f10e583@chaosmail.tech>
On Tue, Jul 28, 2026 at 11:28:11AM +0200, Sasha Finkelstein wrote:
> From: Alba Mendez <me@alba.sh>
>
> The driver was missing locking around register interactions
>
> Signed-off-by: Alba Mendez <me@alba.sh>
> Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
> ---
> drivers/spmi/spmi-apple-controller.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> index aed18b7df15c..2cd4ed1803d4 100644
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
> @@ -14,6 +14,7 @@
> #include <linux/io.h>
> #include <linux/iopoll.h>
> #include <linux/module.h>
> +#include <linux/mutex.h>
> #include <linux/platform_device.h>
> #include <linux/spmi.h>
>
> @@ -35,6 +36,7 @@
>
> struct apple_spmi {
> void __iomem *regs;
> + struct mutex fifo_lock;
> };
>
> #define poll_reg(spmi, reg, val, cond) \
> @@ -73,6 +75,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> size_t i = 0, j;
> int ret;
>
> + mutex_lock(&spmi->fifo_lock);
please use
scoped_guard(mutex, &spmi->fifo_lock) {
> +
> writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
>
> while (i < len) {
> @@ -86,7 +90,7 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>
> ret = apple_spmi_wait_rx_not_empty(ctrl);
> if (ret)
> - return ret;
> + goto out;
>
> reply = readl(spmi->regs + SPMI_RSP_REG);
>
> @@ -94,7 +98,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> while (len_read < ilen) {
> if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
> dev_err(&ctrl->dev, "FIFO lacks reply data, controller stuck?\n");
> - return -EIO;
> + ret = -EIO;
> + goto out;
> }
> rsp = readl(spmi->regs + SPMI_RSP_REG);
> i = 0;
> @@ -107,6 +112,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
> dev_warn(&ctrl->dev, "FIFO has extra data\n");
>
> + mutex_unlock(&spmi->fifo_lock);
}
and avoid the 'goto's
Janne
next prev parent reply other threads:[~2026-08-02 11:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
2026-08-02 9:07 ` Janne Grunau
2026-07-28 9:28 ` [PATCH v2 2/7] spmi: apple: Validate FIFO state Sasha Finkelstein
2026-08-02 9:19 ` Janne Grunau
2026-07-28 9:28 ` [PATCH v2 3/7] spmi: apple: check transaction status Sasha Finkelstein
2026-08-02 10:18 ` Janne Grunau
2026-07-28 9:28 ` [PATCH v2 4/7] spmi: apple: Implement remaining commands Sasha Finkelstein
2026-08-02 11:18 ` Janne Grunau
2026-08-02 11:33 ` Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 5/7] spmi: apple: lock around FIFOs Sasha Finkelstein
2026-08-02 11:27 ` Janne Grunau [this message]
2026-07-28 9:28 ` [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible Sasha Finkelstein
2026-08-02 12:04 ` Janne Grunau
2026-07-28 9:28 ` [PATCH v2 7/7] spmi: apple: interrupt controller functionality Sasha Finkelstein
2026-08-02 13:07 ` Janne Grunau
2026-08-02 13:11 ` Sasha Finkelstein
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=20260802112700.GG806854@robin.jannau.net \
--to=j@jannau.net \
--cc=asahi@lists.linux.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=k@chaosmail.tech \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@alba.sh \
--cc=neal@gompa.dev \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=sven@kernel.org \
/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