Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

spmi: mtk-pmif: Keep spinlock until read is fully done

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 command submission")
Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Fixes: b45b3ccef8c0 ("spmi: mediatek: Add support for MT6873/8192")
Link: https://patch.msgid.link/20260123182039.224314-4-sboyd@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

AngeloGioacchino Del Regno and committed by
Greg Kroah-Hartman
63cbabb0 07811796

+5 -3
+5 -3
drivers/spmi/spmi-mtk-pmif.c
··· 22 22 #define PMIF_CMD_EXT_REG 2 23 23 #define PMIF_CMD_EXT_REG_LONG 3 24 24 25 - #define PMIF_DELAY_US 10 25 + #define PMIF_DELAY_US 2 26 26 #define PMIF_TIMEOUT_US (10 * 1000) 27 27 28 28 #define PMIF_CHAN_OFFSET 0x5 ··· 372 372 /* Send the command. */ 373 373 cmd = (opc << 30) | (sid << 24) | ((len - 1) << 16) | addr; 374 374 pmif_writel(arb, pbus, cmd, inf_reg->ch_send); 375 - raw_spin_unlock_irqrestore(&pbus->lock, flags); 376 375 377 376 /* 378 377 * Wait for Software Interface FSM state to be WFVLDCLR, ··· 381 382 data, GET_SWINF(data) == SWINF_WFVLDCLR, 382 383 PMIF_DELAY_US, PMIF_TIMEOUT_US); 383 384 if (ret < 0) { 385 + raw_spin_unlock_irqrestore(&pbus->lock, flags); 384 386 dev_err(&ctrl->dev, "failed to wait for SWINF_WFVLDCLR\n"); 385 387 return ret; 386 388 } 387 389 388 390 data = pmif_readl(arb, pbus, inf_reg->rdata); 389 - memcpy(buf, &data, len); 390 391 pmif_writel(arb, pbus, 1, inf_reg->ch_rdy); 392 + raw_spin_unlock_irqrestore(&pbus->lock, flags); 393 + 394 + memcpy(buf, &data, len); 391 395 392 396 return 0; 393 397 }