Skip to contentSkip to conversation

spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address

PATCH Superseded Bin Meng 3 participants 6 messages Nov 1, 2014 – Nov 26, 2014 SPI

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v2 1/12 spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address

The ich spi controller driver spi_xfer() tries to align reading address to 64 bytes when doing spi data in, which causes a bug of either infinite loop or a huge size memcpy().

Actually the ich spi controller does not have such requirement of 64 bytes alignment when reading data from spi slave devices.

---
 drivers/spi/ich.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/spi/ich.c +2 -15
index f5c6f3e..c4d3a29 100644
@@ -483,8 +483,6 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 	struct spi_trans *trans = &ich->trans;
 	unsigned type = flags & (SPI_XFER_BEGIN | SPI_XFER_END);
 	int using_cmd = 0;
-	/* Align read transactions to 64-byte boundaries */
-	char buff[ctlr.databytes];
 
 	/* Ee don't support writing partial bytes. */
 	if (bitlen % 8) {
@@ -632,14 +630,9 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 	 */
 	while (trans->bytesout || trans->bytesin) {
 		uint32_t data_length;
-		uint32_t aligned_offset;
-		uint32_t diff;
-
-		aligned_offset = trans->offset & ~(ctlr.databytes - 1);
-		diff = trans->offset - aligned_offset;
 
 		/* SPI addresses are 24 bit only */
-		ich_writel(aligned_offset & 0x00FFFFFF, ctlr.addr);
+		ich_writel(trans->offset & 0x00FFFFFF, ctlr.addr);
 
 		if (trans->bytesout)
 			data_length = min(trans->bytesout, ctlr.databytes);
@@ -673,13 +666,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		}
 
 		if (trans->bytesin) {
-			if (diff) {
-				data_length -= diff;
-				read_reg(ctlr.data, buff, ctlr.databytes);
-				memcpy(trans->in, buff + diff, data_length);
-			} else {
-				read_reg(ctlr.data, trans->in, data_length);
-			}
+			read_reg(ctlr.data, trans->in, data_length);
 			spi_use_in(trans, data_length);
 			if (with_address)
 				trans->offset += data_length;
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v2 1/12 spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address

Hi,

Quoted 7 lines · Bin Meng

The ich spi controller driver spi_xfer() tries to align reading address to 64 bytes when doing spi data in, which causes a bug of either infinite loop or a huge size memcpy().

Actually the ich spi controller does not have such requirement of 64 bytes alignment when reading data from spi slave devices.

Quoted 6 lines
---
 drivers/spi/ich.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

Any update on this series?

If the series is acceptable I could bring it in through the x86 tree since it relates to that SPI controller.

Regards,
Simon

author
#2 lore raw

PATCH v2 1/12 spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address

Hi Simon

Quoted 17 lines · Simon Glass

Hi,

Quoted 7 lines · Bin Meng

The ich spi controller driver spi_xfer() tries to align reading address to 64 bytes when doing spi data in, which causes a bug of either infinite loop or a huge size memcpy().

Actually the ich spi controller does not have such requirement of 64 bytes alignment when reading data from spi slave devices.

Quoted 6 lines
---
 drivers/spi/ich.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
Quoted 5 lines

Any update on this series?

If the series is acceptable I could bring it in through the x86 tree since it relates to that SPI controller.

Thanks for tracking this series. I was asking the same question to Jagan yesterday.

Regards,
Bin

#3 lore raw

PATCH v2 1/12 spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address

Hi Jagan,

Quoted 20 lines · Bin Meng

Hi Simon

Quoted 17 lines · Simon Glass

Hi,

Quoted 13 lines · Bin Meng

The ich spi controller driver spi_xfer() tries to align reading address to 64 bytes when doing spi data in, which causes a bug of either infinite loop or a huge size memcpy().

Actually the ich spi controller does not have such requirement of 64 bytes alignment when reading data from spi slave devices.

---
 drivers/spi/ich.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
Quoted 8 lines
Quoted 5 lines

Any update on this series?

If the series is acceptable I could bring it in through the x86 tree since it relates to that SPI controller.

Thanks for tracking this series. I was asking the same question to Jagan yesterday.

Let me know if you want to pull this through the SPI tree, otherwise I'll go ahead (iwc I'll need to test once more first).

Regards,
Simon

#4 lore raw

PATCH v2 1/12 spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address

Quoted 29 lines · Simon Glass

Hi Jagan,

Quoted 26 lines · Bin Meng

Hi Simon

Quoted 22 lines · Simon Glass

Hi,

Quoted 7 lines · Bin Meng

The ich spi controller driver spi_xfer() tries to align reading address to 64 bytes when doing spi data in, which causes a bug of either infinite loop or a huge size memcpy().

Actually the ich spi controller does not have such requirement of 64 bytes alignment when reading data from spi slave devices.

Quoted 6 lines
---
 drivers/spi/ich.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

Any update on this series?

If the series is acceptable I could bring it in through the x86 tree since it relates to that SPI controller.

Quoted 5 lines
Quoted 2 lines

Thanks for tracking this series. I was asking the same question to Jagan yesterday.

Let me know if you want to pull this through the SPI tree, otherwise I'll go ahead (iwc I'll need to test once more first).

This series change the sf generic code stuff, I will send my review comments. Please hold on this, once everything goes fine I will pick.

thanks!

Signature · 1 line
Jagan.
#5 lore raw

PATCH v2 1/12 spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address

Hi Jagan,

Quoted 30 lines · Jagan Teki
Quoted 29 lines · Simon Glass

Hi Jagan,

Quoted 26 lines · Bin Meng

Hi Simon

Quoted 22 lines · Simon Glass

Hi,

Quoted 7 lines · Bin Meng

The ich spi controller driver spi_xfer() tries to align reading address to 64 bytes when doing spi data in, which causes a bug of either infinite loop or a huge size memcpy().

Actually the ich spi controller does not have such requirement of 64 bytes alignment when reading data from spi slave devices.

Quoted 6 lines
---
 drivers/spi/ich.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

Any update on this series?

If the series is acceptable I could bring it in through the x86 tree since it relates to that SPI controller.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Thanks for tracking this series. I was asking the same question to Jagan yesterday.

Let me know if you want to pull this through the SPI tree, otherwise I'll go ahead (iwc I'll need to test once more first).

This series change the sf generic code stuff, I will send my review comments. Please hold on this, once everything goes fine I will pick.

Sounds good, thanks. Let me know if you want me to test again as a lot has changed since this series was sent.

Regards,
Simon