On 28.09.26 01:57, Mikhail Kshevetskiy wrote:
> From: Miquel Raynal <[email protected]>
>
> As of now, we only use a single operation template when creating SPI
> memory direct mappings. With the idea to extend this possibility to 2,
> rename the template to reflect that we are currently setting the
> "primary" operation, and create a pointer in the same structure to point
> to it.
>
> From a user point of view, the op_tmpl name remains but becomes a
> pointer, leading to minor changes in both the SPI NAND and SPI NOR
> cores.
>
> There is no functional change.
>
> Acked-by: Mark Brown <[email protected]>
> Signed-off-by: Miquel Raynal <[email protected]>
> [Linux commit: 39d0ea33123ffe0214217b529830ad91574c8757]
> Signed-off-by: Mikhail Kshevetskiy <[email protected]>
> ---
> drivers/mtd/nand/spi/core.c | 4 ++--
> drivers/mtd/spi/sf_probe.c | 22 ++++++++++++----------
> drivers/mtd/spi/spi-nor-core.c | 20 ++++++++++++--------
> drivers/spi/airoha_snfi_spi.c | 10 +++++-----
> drivers/spi/spi-aspeed-smc.c | 8 ++++----
> drivers/spi/spi-mem.c | 15 ++++++++-------
> include/spi-mem.h | 3 ++-
> 7 files changed, 45 insertions(+), 37 deletions(-)
>
[...]
> --- a/drivers/mtd/spi/spi-nor-core.c
> +++ b/drivers/mtd/spi/spi-nor-core.c
> @@ -401,15 +401,15 @@ static ssize_t spi_nor_read_data(struct spi_nor *nor,
> loff_t from, size_t len,
> op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
>
> if (CONFIG_IS_ENABLED(SPI_DIRMAP) && nor->dirmap.rdesc) {
> - /*
> - * Record current operation information which may be
> used
> - * when the address or data length exceeds address
> mapping.
> - */
> - memcpy(&nor->dirmap.rdesc->info.op_tmpl, &op,
> - sizeof(struct spi_mem_op));
> + struct spi_mem_op *tmp;
> +
> + /* temporary use another dirmap template */
> + tmp = nor->dirmap.wdesc->info.op_tmpl;
Looks like this should be dirmap.rdesc, not dirmap.wdesc.
> + nor->dirmap.rdesc->info.op_tmpl = &op;
> ret = spi_mem_dirmap_read(nor->dirmap.rdesc,
> op.addr.val, op.data.nbytes,
> op.data.buf.in);
> + nor->dirmap.rdesc->info.op_tmpl = tmp;
> if (ret < 0)
> return ret;
> op.data.nbytes = ret;
> @@ -447,10 +447,14 @@ static ssize_t spi_nor_write_data(struct spi_nor *nor,
> loff_t to, size_t len,
> spi_nor_setup_op(nor, &op, nor->write_proto);
>
> if (CONFIG_IS_ENABLED(SPI_DIRMAP) && nor->dirmap.wdesc) {
> - memcpy(&nor->dirmap.wdesc->info.op_tmpl, &op,
> - sizeof(struct spi_mem_op));
> + struct spi_mem_op *tmp;
> +
> + /* temporary use another dirmap template */
> + tmp = nor->dirmap.wdesc->info.op_tmpl;
> + nor->dirmap.wdesc->info.op_tmpl = &op;
> op.data.nbytes = spi_mem_dirmap_write(nor->dirmap.wdesc,
> op.addr.val,
> op.data.nbytes,
> op.data.buf.out);
> + nor->dirmap.wdesc->info.op_tmpl = tmp;
> } else {
> ret = spi_mem_adjust_op_size(nor->spi, &op);
> if (ret)
[...]