diff mbox series

[U-Boot] spi: spi-mem: Fix read data size issue

Message ID 1562750607-44125-1-git-send-email-ye.li@nxp.com
State Accepted
Commit 535b1fdb8e5e857b9d2747e5f1a1501ec85f327c
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series [U-Boot] spi: spi-mem: Fix read data size issue | expand

Commit Message

Ye Li July 10, 2019, 9:23 a.m. UTC
When slave drivers don't set the max_read_size, the spi-mem should directly
use data.nbytes and not limit to any size. But current logic will limit to
the max_write_size.

Signed-off-by: Ye Li <ye.li@nxp.com>
---
 drivers/spi/spi-mem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Raghavendra, Vignesh July 12, 2019, 12:20 p.m. UTC | #1
On 10/07/19 2:53 PM, Ye Li wrote:
> When slave drivers don't set the max_read_size, the spi-mem should directly
> use data.nbytes and not limit to any size. But current logic will limit to
> the max_write_size.
> 

Indeed. Thanks for catching this!

Acked-by: Vignesh Raghavendra <vigneshr@ti.com>

> Signed-off-by: Ye Li <ye.li@nxp.com>
> ---
>  drivers/spi/spi-mem.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index b86eee7..be440fe 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -423,12 +423,14 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op)
>  		if (slave->max_write_size && len > slave->max_write_size)
>  			return -EINVAL;
>  
> -		if (op->data.dir == SPI_MEM_DATA_IN && slave->max_read_size)
> -			op->data.nbytes = min(op->data.nbytes,
> +		if (op->data.dir == SPI_MEM_DATA_IN) {
> +			if (slave->max_read_size)
> +				op->data.nbytes = min(op->data.nbytes,
>  					      slave->max_read_size);
> -		else if (slave->max_write_size)
> +		} else if (slave->max_write_size) {
>  			op->data.nbytes = min(op->data.nbytes,
>  					      slave->max_write_size - len);
> +		}
>  
>  		if (!op->data.nbytes)
>  			return -EINVAL;
>
Jagan Teki July 15, 2019, 7:32 a.m. UTC | #2
On Wed, Jul 10, 2019 at 2:54 PM Ye Li <ye.li@nxp.com> wrote:
>
> When slave drivers don't set the max_read_size, the spi-mem should directly
> use data.nbytes and not limit to any size. But current logic will limit to
> the max_write_size.
>
> Signed-off-by: Ye Li <ye.li@nxp.com>
> ---
>  drivers/spi/spi-mem.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index b86eee7..be440fe 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -423,12 +423,14 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op)
>                 if (slave->max_write_size && len > slave->max_write_size)
>                         return -EINVAL;
>
> -               if (op->data.dir == SPI_MEM_DATA_IN && slave->max_read_size)
> -                       op->data.nbytes = min(op->data.nbytes,
> +               if (op->data.dir == SPI_MEM_DATA_IN) {
> +                       if (slave->max_read_size)
> +                               op->data.nbytes = min(op->data.nbytes,
>                                               slave->max_read_size);
> -               else if (slave->max_write_size)
> +               } else if (slave->max_write_size) {
>                         op->data.nbytes = min(op->data.nbytes,
>                                               slave->max_write_size - len);
> +               }

Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
Jagan Teki July 16, 2019, 11:50 a.m. UTC | #3
On Wed, Jul 10, 2019 at 2:54 PM Ye Li <ye.li@nxp.com> wrote:
>
> When slave drivers don't set the max_read_size, the spi-mem should directly
> use data.nbytes and not limit to any size. But current logic will limit to
> the max_write_size.
>
> Signed-off-by: Ye Li <ye.li@nxp.com>
> ---
>  drivers/spi/spi-mem.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

Applied to u-boot-spi/master
diff mbox series

Patch

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index b86eee7..be440fe 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -423,12 +423,14 @@  int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op)
 		if (slave->max_write_size && len > slave->max_write_size)
 			return -EINVAL;
 
-		if (op->data.dir == SPI_MEM_DATA_IN && slave->max_read_size)
-			op->data.nbytes = min(op->data.nbytes,
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			if (slave->max_read_size)
+				op->data.nbytes = min(op->data.nbytes,
 					      slave->max_read_size);
-		else if (slave->max_write_size)
+		} else if (slave->max_write_size) {
 			op->data.nbytes = min(op->data.nbytes,
 					      slave->max_write_size - len);
+		}
 
 		if (!op->data.nbytes)
 			return -EINVAL;