From: minyard@acm.org
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
Corey Minyard <cminyard@mvista.com>,
Alistair Francis <alistair.francis@xilinx.com>,
KONRAD Frederic <fred.konrad@greensocs.com>
Subject: [Qemu-devel] [PATCH] i2c: Add asserts for second smbus i2c_start_transfer()
Date: Mon, 24 Oct 2016 10:10:54 -0500 [thread overview]
Message-ID: <1477321854-8080-1-git-send-email-minyard@acm.org> (raw)
From: Corey Minyard <cminyard@mvista.com>
Some SMBus operations restart the transfer to convert from
write to read mode without an intervening i2c_end_transfer().
The second call cannot fail, so the return code is unchecked,
but this causes Coverity to complain. So add some asserts
and documentation about this.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
hw/i2c/core.c | 5 ++++-
hw/i2c/smbus.c | 6 +++---
2 files changed, 7 insertions(+), 4 deletions(-)
I tested this with the IPMI SMbus driver for a while.
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index bd8f167..b9dea79 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -88,7 +88,10 @@ int i2c_bus_busy(I2CBus *bus)
return !QLIST_EMPTY(&bus->current_devs);
}
-/* Returns non-zero if the address is not valid. */
+/* Returns non-zero if the address is not valid. If this is called
+ again without an intervening i2c_end_transfer(), like in the SMBus
+ case where the operation is switched from write to read, this
+ function will not rescan the bus and thus cannot fail. */
/* TODO: Make this handle multiple masters. */
int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
{
diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
index 3979b3d..bf46d22 100644
--- a/hw/i2c/smbus.c
+++ b/hw/i2c/smbus.c
@@ -248,7 +248,7 @@ int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command)
return -1;
}
i2c_send(bus, command);
- i2c_start_transfer(bus, addr, 1);
+ assert(!i2c_start_transfer(bus, addr, 1));
data = i2c_recv(bus);
i2c_nack(bus);
i2c_end_transfer(bus);
@@ -273,7 +273,7 @@ int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command)
return -1;
}
i2c_send(bus, command);
- i2c_start_transfer(bus, addr, 1);
+ assert(!i2c_start_transfer(bus, addr, 1));
data = i2c_recv(bus);
data |= i2c_recv(bus) << 8;
i2c_nack(bus);
@@ -302,7 +302,7 @@ int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data)
return -1;
}
i2c_send(bus, command);
- i2c_start_transfer(bus, addr, 1);
+ assert(!i2c_start_transfer(bus, addr, 1));
len = i2c_recv(bus);
if (len > 32) {
len = 0;
--
2.7.4
next reply other threads:[~2016-10-24 15:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-24 15:10 minyard [this message]
2016-10-24 15:15 ` [Qemu-devel] [PATCH] i2c: Add asserts for second smbus i2c_start_transfer() Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1477321854-8080-1-git-send-email-minyard@acm.org \
--to=minyard@acm.org \
--cc=alistair.francis@xilinx.com \
--cc=cminyard@mvista.com \
--cc=fred.konrad@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).