Skip to contentSkip to conversation

SPI: Fix 32 bit transfers in mxc_spi.c

PATCH Superseded Magnus Lilja 3 participants 5 messages Jan 17, 2010 – Feb 8, 2010

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 SPI: Fix 32 bit transfers in mxc_spi.c

Commit f9b6a1575d9f1ca192e4cb60e547aa66f08baa3f, "i.MX31: fix SPI driver for shorter than 32 bit" broke 32 bit transfers. This patch makes single 32 bit transfer work again.

Transfer lengths that are known not to work will abort and print an error message.

Tested on i.MX31 Litekit and i.MX31 PDK using 32 bit transfers to the MC13783/ATLAS chip (using the 'date' command).

---

As discussed on the mailing list, Guennadi Liakhovetski thinks that all transfers > 16 bits are broken. This patch fixes the 32 bit case and makes sure the user is notified if a broken bitlength is used.

 drivers/spi/mxc_spi.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/spi/mxc_spi.c +9 -0
index fad9840..93c2bd7 100644
@@ -131,6 +131,13 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		return 1;
 	}
 
+	/* This driver is currently partly broken, alert the user */
+	if (bitlen > 16 && bitlen != 32) {
+		printf("Error: SPI transfer with bitlen=%d is broken.\n",
+		       bitlen);
+		return 1;
+	}
+
 	for (i = 0, in_l = (u32 *)din, out_l = (u32 *)dout;
 	     i < n_blks;
 	     i++, in_l++, out_l++, bitlen -= 32) {
@@ -142,6 +149,8 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 				*(u8 *)din = data;
 			else if (bitlen < 17)
 				*(u16 *)din = data;
+			else
+				*in_l = data;
 		}
 	}
 
Signature · 1 line
1.5.6
#1 lore raw

PATCH v2 1/1 SPI: Fix 32 bit transfers in mxc_spi.c

Dear Feng,

can you please take care of this?

Quoted 11 lines · In message <[email protected]> Magnus…

Commit f9b6a1575d9f1ca192e4cb60e547aa66f08baa3f, "i.MX31: fix SPI driver for shorter than 32 bit" broke 32 bit transfers. This patch makes single 32 bit transfer work again.

Transfer lengths that are known not to work will abort and print an error message.

Tested on i.MX31 Litekit and i.MX31 PDK using 32 bit transfers to the MC13783/ATLAS chip (using the 'date' command).

Quoted 8 lines

---

As discussed on the mailing list, Guennadi Liakhovetski thinks that all transfers > 16 bits are broken. This patch fixes the 32 bit case and makes sure the user is notified if a broken bitlength is used.

 drivers/spi/mxc_spi.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

Best regards,

Wolfgang Denk

Signature · 8 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A secure program has to be robust: it  must  be  able  to  deal  with
conditions  that "can't happen", whether user input, program error or
library/etc. This is basic damage  control.  Buffer  overflow  errors
have nothing to do with security, but everything with stupidity.
                 -- Wietse Venema in <[email protected]>
#2 lore raw

PATCH v2 1/1 SPI: Fix 32 bit transfers in mxc_spi.c

Dear Feng and Tom,

Is this in a queue somewhere to be merged? If not, could you please apply this and make a pull request for it?

Bset regards, Magnus Lilja

Wolfgang Denk skrev:

Quoted 31 lines

Dear Feng,

can you please take care of this?

Quoted 11 lines · In message <[email protected]> Magnus…

Commit f9b6a1575d9f1ca192e4cb60e547aa66f08baa3f, "i.MX31: fix SPI driver for shorter than 32 bit" broke 32 bit transfers. This patch makes single 32 bit transfer work again.

Transfer lengths that are known not to work will abort and print an error message.

Tested on i.MX31 Litekit and i.MX31 PDK using 32 bit transfers to the MC13783/ATLAS chip (using the 'date' command).

Quoted 8 lines

---

As discussed on the mailing list, Guennadi Liakhovetski thinks that all transfers > 16 bits are broken. This patch fixes the 32 bit case and makes sure the user is notified if a broken bitlength is used.

 drivers/spi/mxc_spi.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

Best regards,

Wolfgang Denk

#3 lore raw

PATCH v2 1/1 SPI: Fix 32 bit transfers in mxc_spi.c

In reply to Magnus Lilja
Quoted 25 lines · Magnus Lilja

Commit f9b6a1575d9f1ca192e4cb60e547aa66f08baa3f, "i.MX31: fix SPI driver for shorter than 32 bit" broke 32 bit transfers. This patch makes single 32 bit transfer work again.

Transfer lengths that are known not to work will abort and print an error message.

Tested on i.MX31 Litekit and i.MX31 PDK using 32 bit transfers to the MC13783/ATLAS chip (using the 'date' command).

---

As discussed on the mailing list, Guennadi Liakhovetski thinks that all transfers > 16 bits are broken. This patch fixes the 32 bit case and makes sure the user is notified if a broken bitlength is used.

 drivers/spi/mxc_spi.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/spi/mxc_spi.c +0 -0
index fad9840..93c2bd7 100644

drivers/spi/mxc_spi.c int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, · line 135

Quoted 5 lines
drivers/spi/mxc_spi.c +2 -0
@@ -131,6 +131,13 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		return 1;
 	}
 
+	/* This driver is currently partly broken, alert the user */
+	if (bitlen > 16 && bitlen != 32) {

I believe this check can be improved
The transfer loops over 32 bit blks.
so bitlen that are multiples of 32 should work.
so

bitlen != 32

can change to

(bitlen % 32)

Tom

Quoted 17 lines
drivers/spi/mxc_spi.c +7 -0
+		printf("Error: SPI transfer with bitlen=%d is broken.\n",
+		       bitlen);
+		return 1;
+	}
+
 	for (i = 0, in_l = (u32 *)din, out_l = (u32 *)dout;
 	     i < n_blks;
 	     i++, in_l++, out_l++, bitlen -= 32) {
@@ -142,6 +149,8 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 				*(u8 *)din = data;
 			else if (bitlen < 17)
 				*(u16 *)din = data;
+			else
+				*in_l = data;
 		}
 	}
 
#4 lore raw

PATCH v2 1/1 SPI: Fix 32 bit transfers in mxc_spi.c

Tom skrev:

Quoted 38 lines
Quoted 25 lines · Magnus Lilja

Commit f9b6a1575d9f1ca192e4cb60e547aa66f08baa3f, "i.MX31: fix SPI driver for shorter than 32 bit" broke 32 bit transfers. This patch makes single 32 bit transfer work again.

Transfer lengths that are known not to work will abort and print an error message.

Tested on i.MX31 Litekit and i.MX31 PDK using 32 bit transfers to the MC13783/ATLAS chip (using the 'date' command).

---

As discussed on the mailing list, Guennadi Liakhovetski thinks that all transfers > 16 bits are broken. This patch fixes the 32 bit case and makes sure the user is notified if a broken bitlength is used.

 drivers/spi/mxc_spi.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/spi/mxc_spi.c +0 -0
index fad9840..93c2bd7 100644

drivers/spi/mxc_spi.c int spi_xfer(struct spi_slave *slave, unsigned · line 136

Quoted 6 lines
drivers/spi/mxc_spi.c +2 -0
@@ -131,6 +131,13 @@ int spi_xfer(struct spi_slave *slave, unsigned
 int bitlen, const void *dout,
         return 1;
     }
 
+    /* This driver is currently partly broken, alert the user */
+    if (bitlen > 16 && bitlen != 32) {

I believe this check can be improved
The transfer loops over 32 bit blks.
so bitlen that are multiples of 32 should work.
so

Quoted 5 lines

bitlen != 32

can change to

(bitlen % 32)

Patch updated, but I want to test it first. Having tftp problems at the moment with my newly re-installed machine, will post new version as soon as possible.

Regards/Magnus