aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAndreas Färber <andreas.faerber@web.de>2013-01-16 01:57:56 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2013-01-16 12:14:20 -0600
commitcb5ef3fa1871522a0886627033459e94bd537fb7 (patch)
treeec94c5b0f0514297227eb6de0a0e432f2affe5a2 /hw
parent6d0b430176e3571af0e1596276078f05bfe1c5a5 (diff)
downloadqemu-cb5ef3fa1871522a0886627033459e94bd537fb7.zip
qemu-cb5ef3fa1871522a0886627033459e94bd537fb7.tar.gz
qemu-cb5ef3fa1871522a0886627033459e94bd537fb7.tar.bz2
tmp105: Fix I2C protocol bug
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 <alex.horn@cs.ox.ac.uk> Signed-off-by: Andreas Färber <andreas.faerber@web.de> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/tmp105.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/hw/tmp105.c b/hw/tmp105.c
index 0ade4eb..10d94c9 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);
}