]> Git Repo - qemu.git/commitdiff
tmp105: Fix I2C protocol bug
authorAndreas Färber <[email protected]>
Wed, 16 Jan 2013 00:57:56 +0000 (01:57 +0100)
committerAnthony Liguori <[email protected]>
Wed, 16 Jan 2013 18:14:20 +0000 (12:14 -0600)
An early length postincrement in the TMP105's I2C TX path led to
transfers of more than one byte to place the second byte in the third
byte's place within the buffer and the third byte to get discarded.

Fix this by explictly incrementing the length after the checks but
before the callback is called, which again checks the length.

Adjust the Coding Style while at it.

Signed-off-by: Alex Horn <[email protected]>
Signed-off-by: Andreas Färber <[email protected]>
Reviewed-by: Anthony Liguori <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
hw/tmp105.c

index 0ade4eb6bd9766d7d0fffff3d14747e8c2971e36..10d94c903ca4208773606bac5749fc2a7e677219 100644 (file)
@@ -153,11 +153,14 @@ static int tmp105_tx(I2CSlave *i2c, uint8_t data)
 {
     TMP105State *s = (TMP105State *) i2c;
 
-    if (!s->len ++)
+    if (s->len == 0) {
         s->pointer = data;
-    else {
-        if (s->len <= 2)
+        s->len++;
+    } else {
+        if (s->len <= 2) {
             s->buf[s->len - 1] = data;
+        }
+        s->len++;
         tmp105_write(s);
     }
 
This page took 0.025219 seconds and 4 git commands to generate.