From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byj0N-0006VR-GB for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:25:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byj0L-0007Vs-Kf for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:25:47 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:47421) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byj0L-0007O9-Bv for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:25:45 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1byj0K-0002TE-7O for qemu-devel@nongnu.org; Mon, 24 Oct 2016 18:25:44 +0100 From: Peter Maydell Date: Mon, 24 Oct 2016 18:25:28 +0100 Message-Id: <1477329928-26414-33-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1477329928-26414-1-git-send-email-peter.maydell@linaro.org> References: <1477329928-26414-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PULL 32/32] i2c: Add asserts for second smbus i2c_start_transfer() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Corey Minyard 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 Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/i2c/core.c | 7 ++++++- hw/i2c/smbus.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hw/i2c/core.c b/hw/i2c/core.c index bd8f167..abd4c4c 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -88,7 +88,12 @@ 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..5b4dd3e 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus.c @@ -248,7 +248,9 @@ int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command) return -1; } i2c_send(bus, command); - i2c_start_transfer(bus, addr, 1); + if (i2c_start_transfer(bus, addr, 1)) { + assert(0); + } data = i2c_recv(bus); i2c_nack(bus); i2c_end_transfer(bus); @@ -273,7 +275,9 @@ int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command) return -1; } i2c_send(bus, command); - i2c_start_transfer(bus, addr, 1); + if (i2c_start_transfer(bus, addr, 1)) { + assert(0); + } data = i2c_recv(bus); data |= i2c_recv(bus) << 8; i2c_nack(bus); @@ -302,7 +306,9 @@ 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); + if (i2c_start_transfer(bus, addr, 1)) { + assert(0); + } len = i2c_recv(bus); if (len > 32) { len = 0; -- 2.7.4