提交 cb5ef3fa 编写于 作者: A Andreas Färber 提交者: Anthony Liguori

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: NAlex Horn <alex.horn@cs.ox.ac.uk>
Signed-off-by: NAndreas Färber <andreas.faerber@web.de>
Reviewed-by: NAnthony Liguori <aliguori@us.ibm.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 6d0b4301
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册