From nobody Sun Feb 8 16:50:50 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A3CD284880; Fri, 23 Jan 2026 18:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769192442; cv=none; b=RHjhuylfTqAbb+D+8XaWbiRaJu8vYWZJ4/i2mvhTQnD19THzRalEVTZE46UAmithmPAYg56tbDGwKgpLlJfpFxk38vE7dsYv+zOiUuT9D//XvrRZZvaWQDH0chUr1IMcyWWOzK4lCsy10fIXS9h64Ha2moUjw7Vq8F1opf2T+C0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769192442; c=relaxed/simple; bh=CAUdVWighr0KoYqDOZXRB5L55TyWyaqrDVdLRpeXvX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AuCVc1g3pTtQgqg79aSjYuJc0AEMFAXKPx46m9sZuh390XXcZqAiT57J5H1X9SR91rqQoEslUVltO7bDh1bNLei99ro0apCJvykm/Tt6gHk+FqIl775ycQb2ZHEdO0pgp6br6gFU/gYWMRMQ3B+pVIeUDugRLCh3E7+gx0f9Aik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h/6q/eN/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h/6q/eN/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8813C116D0; Fri, 23 Jan 2026 18:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769192442; bh=CAUdVWighr0KoYqDOZXRB5L55TyWyaqrDVdLRpeXvX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h/6q/eN/UcEozvC7dxiuplTFX1V6wepXZaqpFQEj4y9ogg5OYOqQ3H3vuxEJC33zd f3JccCnZ5YOczQ5mOl/K9DpvBFUfGR6cRtMyiOLzBeNwsKIM0C6rbyIlBm4+teDG20 hndZgVG1GrBnKpNEy1/M1/lTCQzJ865nJIMEBCas0lMNjYB00DHQk7lj3XhNIDNIxM oGx0hoo7gJASrEfYchd7H5T92/HGapLtqEqHUWnSklzupmzEHwyJAmjfIPpqvFX7hN +HountKdB3enW7eYQs+WoeRJo8rkInoKGuE8VfrwBquS//5u0AkXGhCqI0Smaso/vu vlgNGy9Ke2A9w== From: Stephen Boyd To: Greg Kroah-Hartman Cc: AngeloGioacchino Del Regno , linux-kernel@vger.kernel.org, patches@lists.linux.dev, =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= , Chen-Yu Tsai Subject: [PATCH 03/10] spmi: mtk-pmif: Keep spinlock until read is fully done Date: Fri, 23 Jan 2026 10:20:31 -0800 Message-ID: <20260123182039.224314-4-sboyd@kernel.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20260123182039.224314-1-sboyd@kernel.org> References: <20260123182039.224314-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: AngeloGioacchino Del Regno Move the spin unlocking to after reading the contents of the PMIF_SWINF_(x)_RDATA_31_0 register in pmif_spmi_read_cmd(): since this is the only register that we can read to get the data from all of the arbitered busses, a concurrent request for reading (especially on a busy arbiter) will show a race condition and a unexpected or corrupted value may be read. Doing the entire read sequence while spin locked guarantees that concurrent access to the arbiter doesn't happen. Fixes: f200fff8d019 ("spmi: mtk-pmif: Serialize PMIF status check and comma= nd submission") Reviewed-by: N=C3=ADcolas F. R. A. Prado Reviewed-by: Chen-Yu Tsai Signed-off-by: AngeloGioacchino Del Regno Signed-off-by: Stephen Boyd --- drivers/spmi/spmi-mtk-pmif.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c index 68f458587c67..9f416b231ab8 100644 --- a/drivers/spmi/spmi-mtk-pmif.c +++ b/drivers/spmi/spmi-mtk-pmif.c @@ -22,7 +22,7 @@ #define PMIF_CMD_EXT_REG 2 #define PMIF_CMD_EXT_REG_LONG 3 =20 -#define PMIF_DELAY_US 10 +#define PMIF_DELAY_US 2 #define PMIF_TIMEOUT_US (10 * 1000) =20 #define PMIF_CHAN_OFFSET 0x5 @@ -372,7 +372,6 @@ static int pmif_spmi_read_cmd(struct spmi_controller *c= trl, u8 opc, u8 sid, /* Send the command. */ cmd =3D (opc << 30) | (sid << 24) | ((len - 1) << 16) | addr; pmif_writel(arb, pbus, cmd, inf_reg->ch_send); - raw_spin_unlock_irqrestore(&pbus->lock, flags); =20 /* * Wait for Software Interface FSM state to be WFVLDCLR, @@ -382,13 +381,16 @@ static int pmif_spmi_read_cmd(struct spmi_controller = *ctrl, u8 opc, u8 sid, data, GET_SWINF(data) =3D=3D SWINF_WFVLDCLR, PMIF_DELAY_US, PMIF_TIMEOUT_US); if (ret < 0) { + raw_spin_unlock_irqrestore(&pbus->lock, flags); dev_err(&ctrl->dev, "failed to wait for SWINF_WFVLDCLR\n"); return ret; } =20 data =3D pmif_readl(arb, pbus, inf_reg->rdata); - memcpy(buf, &data, len); pmif_writel(arb, pbus, 1, inf_reg->ch_rdy); + raw_spin_unlock_irqrestore(&pbus->lock, flags); + + memcpy(buf, &data, len); =20 return 0; } --=20 https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git