merged.

If there are any review comments, we can apply more patches on top,
but I needed these to all be staged for some build testing.

Bruce

In message: [PATCH][linux-yocto][linux-yocto 
v5.10/standard/sdkv5.4/xlnx-soc][linux-yocto-dev standard/xlnx-soc] spi: 
spi-mem: fix xfers for opcode more then 1 byte
on 13/05/2021 Yun Zhou wrote:

> opcode in struct spi_mem_op is type u16, 2 bytes. If a opcode more then
> 1 byte, the MSB may lost, and msg.actual_length will be not equal to
> totalxferlen, spi_mem_exec_op() will return -EIO.
> 
> Signed-off-by: Yun Zhou <[email protected]>
> ---
>  drivers/spi/spi-mem.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index 8d3042c1ac0e..53778a064293 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -346,22 +346,27 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct 
> spi_mem_op *op)
>  
>       spi_message_init(&msg);
>  
> -     tmpbuf[0] = op->cmd.opcode;
> +     if (op->cmd.nbytes == 1)
> +             tmpbuf[0] = op->cmd.opcode;
> +     else { /* nbytes == 2 */
> +             tmpbuf[0] = op->cmd.opcode >> 8;
> +             tmpbuf[1] = op->cmd.opcode;
> +     }
>       xfers[xferpos].tx_buf = tmpbuf;
>       xfers[xferpos].len = op->cmd.nbytes;
>       xfers[xferpos].tx_nbits = op->cmd.buswidth;
>       spi_message_add_tail(&xfers[xferpos], &msg);
>       xferpos++;
> -     totalxferlen++;
> +     totalxferlen += op->cmd.nbytes;
>  
>       if (op->addr.nbytes) {
>               int i;
>  
>               for (i = 0; i < op->addr.nbytes; i++)
> -                     tmpbuf[i + 1] = op->addr.val >>
> +                     tmpbuf[i + totalxferlen] = op->addr.val >>
>                                       (8 * (op->addr.nbytes - i - 1));
>  
> -             xfers[xferpos].tx_buf = tmpbuf + 1;
> +             xfers[xferpos].tx_buf = tmpbuf + totalxferlen;
>               xfers[xferpos].len = op->addr.nbytes;
>               xfers[xferpos].tx_nbits = op->addr.buswidth;
>               spi_message_add_tail(&xfers[xferpos], &msg);
> @@ -370,8 +375,8 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct 
> spi_mem_op *op)
>       }
>  
>       if (op->dummy.nbytes) {
> -             memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
> -             xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
> +             memset(tmpbuf + totalxferlen, 0xff, op->dummy.nbytes);
> +             xfers[xferpos].tx_buf = tmpbuf + totalxferlen;
>               xfers[xferpos].len = op->dummy.nbytes;
>               xfers[xferpos].tx_nbits = op->dummy.buswidth;
>               xfers[xferpos].dummy = op->dummy.nbytes * 8;
> -- 
> 2.26.1
> 
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#9878): 
https://lists.yoctoproject.org/g/linux-yocto/message/9878
Mute This Topic: https://lists.yoctoproject.org/mt/82816087/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to