From cb5ef3fa1871522a0886627033459e94bd537fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 16 Jan 2013 01:57:56 +0100 Subject: [PATCH] tmp105: Fix I2C protocol bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Andreas Färber Reviewed-by: Anthony Liguori Signed-off-by: Anthony Liguori --- hw/tmp105.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/tmp105.c b/hw/tmp105.c index 0ade4eb6bd..10d94c903c 100644 --- a/hw/tmp105.c +++ b/hw/tmp105.c @@ -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); } -- GitLab