[PATCH v2 1/2] spi: spi-mem: Protect dirmap_create() with spi_mem_access_start/end
Chin-Ting Kuo
chin-ting_kuo at aspeedtech.com
Sun Jan 18 04:38:43 PST 2026
Hi Paul,
Thanks for the review.
> -----Original Message-----
> From: Paul Menzel <pmenzel at molgen.mpg.de>
> Sent: Sunday, January 18, 2026 7:47 AM
> Subject: Re: [PATCH v2 1/2] spi: spi-mem: Protect dirmap_create() with
> spi_mem_access_start/end
>
> Dear Chin-Ting,
>
>
> Thank you for your patch.
>
> Am 17.01.26 um 14:42 schrieb Chin-Ting Kuo:
> > 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.
>
> Do you have a reproducer for this issue to test your patch? If yes, it’d be
> great, if you documented it.
>
Yes, I verified this with a scenario where an SPI TPM is connected to CS0 of a SPI controller, while an SPI NOR flash is connected to CS1 of the same controller. I will add this description to the next patch version.
> > Signed-off-by: Chin-Ting Kuo <chin-ting_kuo at aspeedtech.com>
> > ---
> > drivers/spi/spi-mem.c | 11 ++++++++++-
> > 1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index
> > c8b2add2640e..85702a77b3c8 100644
> > --- a/drivers/spi/spi-mem.c
> > +++ b/drivers/spi/spi-mem.c
> > @@ -708,9 +708,18 @@ spi_mem_dirmap_create(struct spi_mem *mem,
> >
> > desc->mem = mem;
> > desc->info = *info;
> > - if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create)
> > + if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) {
> > + ret = spi_mem_access_start(mem);
> > + if (ret) {
> > + kfree(desc);
> > + return ERR_PTR(ret);
> > + }
> > +
> > ret = ctlr->mem_ops->dirmap_create(desc);
> >
> > + spi_mem_access_end(mem);
> > + }
> > +
> > if (ret) {
> > desc->nodirmap = true;
> > if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))
>
> Reviewed-by: Paul Menzel <pmenzel at molgen.mpg.de>
>
>
> Kind regards,
>
> Paul
More information about the linux-arm-kernel
mailing list