Skip to content

Commit 53f826f

Browse files
chintingkuobroonie
authored andcommitted
spi: spi-mem: Protect dirmap_create() with spi_mem_access_start/end
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>
1 parent 63804fe commit 53f826f

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
@@ -708,9 +708,18 @@ spi_mem_dirmap_create(struct spi_mem *mem,
708708

709709
desc->mem = mem;
710710
desc->info = *info;
711-
if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create)
711+
if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) {
712+
ret = spi_mem_access_start(mem);
713+
if (ret) {
714+
kfree(desc);
715+
return ERR_PTR(ret);
716+
}
717+
712718
ret = ctlr->mem_ops->dirmap_create(desc);
713719

720+
spi_mem_access_end(mem);
721+
}
722+
714723
if (ret) {
715724
desc->nodirmap = true;
716725
if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))

0 commit comments

Comments
 (0)