Skip to contentSkip to conversation

spi: spi-mem-nodm: Fix read data size issue

PATCH In review Bin Meng 4 participants 4 messages Jul 28, 2021 – Aug 3, 2021 SPI

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/1 spi: spi-mem-nodm: 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.

This commit mirrors the same changes in the dm version done in commit 535b1fdb8e5e ("spi: spi-mem: Fix read data size issue").

---

 drivers/spi/spi-mem-nodm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/spi/spi-mem-nodm.c +6 -4
index a228c808c7..77ddb19a9f 100644
@@ -93,12 +93,14 @@ int spi_mem_adjust_op_size(struct spi_slave *slave,
 	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,
-				      slave->max_read_size);
-	else if (slave->max_write_size)
+	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) {
 		op->data.nbytes = min(op->data.nbytes,
 				      slave->max_write_size - len);
+	}
 
 	if (!op->data.nbytes)
 		return -EINVAL;
Signature · 1 line
2.25.1
#1 lore raw

+Tom, Simon,

Quoted 3 lines · Bin Meng

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.

With the push towards using DM, do we really need to maintain the nodm version anymore? Are there any users left? If there are, I think they should migrate to using DM instead of trying to fix depreciated code.

Thoughts?

Quoted 36 lines

This commit mirrors the same changes in the dm version done in commit 535b1fdb8e5e ("spi: spi-mem: Fix read data size issue").

---

 drivers/spi/spi-mem-nodm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/spi/spi-mem-nodm.c +6 -4
index a228c808c7..77ddb19a9f 100644
@@ -93,12 +93,14 @@ int spi_mem_adjust_op_size(struct spi_slave *slave,
 	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,
-				      slave->max_read_size);
-	else if (slave->max_write_size)
+	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) {
 		op->data.nbytes = min(op->data.nbytes,
 				      slave->max_write_size - len);
+	}
 
 	if (!op->data.nbytes)
 		return -EINVAL;
Signature · 1 line
2.25.1
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#2 lore raw
Quoted 10 lines · Pratyush Yadav

+Tom, Simon,

Quoted 3 lines · Bin Meng

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.

With the push towards using DM, do we really need to maintain the nodm version anymore? Are there any users left? If there are, I think they should migrate to using DM instead of trying to fix depreciated code.

The users here are likely SPL without DM and SPL_DM is not required.

Signature · 1 line
Tom
#3 lore raw
In reply to Bin Meng
Quoted 10 lines · Bin Meng

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.

This commit mirrors the same changes in the dm version done in commit 535b1fdb8e5e ("spi: spi-mem: Fix read data size issue").

---

Applied to u-boot-spi/master