Skip to contentSkip to conversation

spi: spi-mem: Fix read data size issue

PATCH New Ye Li 3 participants 4 messages Jul 10, 2019 – Jul 16, 2019 SPI

lore
Share & tools
lore

Ye Li

author
#0 lore raw

PATCH 1/1 spi: spi-mem: Fix read data size issue

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.

---
 drivers/spi/spi-mem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/spi/spi-mem.c +5 -3
index b86eee7..be440fe 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 spi: spi-mem: Fix read data size issue

Quoted 4 lines · Ye Li

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!

Quoted 28 lines
---
 drivers/spi/spi-mem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/spi/spi-mem.c +5 -3
index b86eee7..be440fe 100644
@@ -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;
Signature · 2 lines
Regards
Vignesh
#2 lore raw

PATCH 1/1 spi: spi-mem: Fix read data size issue

In reply to Ye Li
Quoted 19 lines · Ye Li

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.

---
 drivers/spi/spi-mem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/spi/spi-mem.c +0 -1
index b86eee7..be440fe 100644
@@ -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)

drivers/spi/spi-mem.c int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op) · line 433

Quoted 10 lines
drivers/spi/spi-mem.c +5 -2
-                       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);
+               }
#3 lore raw

PATCH 1/1 spi: spi-mem: Fix read data size issue

In reply to Ye Li
Quoted 9 lines · Ye Li

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.

---
 drivers/spi/spi-mem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Applied to u-boot-spi/master