Skip to content

Commit 2b0babc

Browse files
chintingkuoSasha Levin
authored andcommitted
spi: spi-mem: Protect dirmap_create() with spi_mem_access_start/end
[ Upstream commit 53f826ff5e0e3ecb279862ca7cce1491b94bb017 ] spi_mem_dirmap_create() may reconfigure controller-wide settings, which can interfere with concurrent transfers to other devices sharing the same SPI controller but using different chip selects. Wrap the ->dirmap_create() callback with spi_mem_access_start() and spi_mem_access_end() to serialize access and prevent cross-CS interference during dirmap creation. This patch has been verified on a setup where a SPI TPM is connected to CS0 of a SPI controller, while a SPI NOR flash is connected to CS1 of the same controller. Without this patch, spi_mem_dirmap_create() for the SPI NOR flash interferes with ongoing SPI TPM data transfers, resulting in failure to create the TPM device. This was tested on an ASPEED AST2700 EVB. Signed-off-by: Chin-Ting Kuo <chin-ting_kuo@aspeedtech.com> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Link: https://patch.msgid.link/20260120123005.1392071-2-chin-ting_kuo@aspeedtech.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8637b3d commit 2b0babc

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

drivers/spi/spi-mem.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,18 @@ spi_mem_dirmap_create(struct spi_mem *mem,
540540

541541
desc->mem = mem;
542542
desc->info = *info;
543-
if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create)
543+
if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) {
544+
ret = spi_mem_access_start(mem);
545+
if (ret) {
546+
kfree(desc);
547+
return ERR_PTR(ret);
548+
}
549+
544550
ret = ctlr->mem_ops->dirmap_create(desc);
545551

552+
spi_mem_access_end(mem);
553+
}
554+
546555
if (ret) {
547556
desc->nodirmap = true;
548557
if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))

0 commit comments

Comments
 (0)