Skip to contentSkip to conversation

spi/spidev: check message size before copying

PATCH New Domen Puncer 1 participant 1 message May 23, 2007 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi/spidev: check message size before copying

Message size needs to be checked before copying, or bad things could happen.

---
 drivers/spi/spidev.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/spi/spidev.c +6 -6
Index: work-powerpc.git/drivers/spi/spidev.c
===================================================================
@@ -168,6 +168,12 @@ static int spidev_message(struct spidev_
 			n--, k_tmp++, u_tmp++) {
 		k_tmp->len = u_tmp->len;
 
+		total += k_tmp->len;
+		if (total > bufsiz) {
+			status = -EMSGSIZE;
+			goto done;
+		}
+
 		if (u_tmp->rx_buf) {
 			k_tmp->rx_buf = buf;
 			if (!access_ok(VERIFY_WRITE, u_tmp->rx_buf, u_tmp->len))
@@ -179,12 +185,6 @@ static int spidev_message(struct spidev_
 					u_tmp->len))
 				goto done;
 		}
-
-		total += k_tmp->len;
-		if (total > bufsiz) {
-			status = -EMSGSIZE;
-			goto done;
-		}
 		buf += k_tmp->len;
 
 		k_tmp->cs_change = !!u_tmp->cs_change;

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/