[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 32/32] i2c: Add asserts for second smbus i2c_start_tr
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PULL 32/32] i2c: Add asserts for second smbus i2c_start_transfer() |
Date: |
Mon, 24 Oct 2016 18:25:28 +0100 |
From: Corey Minyard <address@hidden>
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 <address@hidden>
Reviewed-by: Peter Maydell <address@hidden>
Signed-off-by: Peter Maydell <address@hidden>
---
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
- [Qemu-devel] [PULL 10/32] hw/ptimer: Add "continuous trigger" policy, (continued)
- [Qemu-devel] [PULL 10/32] hw/ptimer: Add "continuous trigger" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 21/32] tests: Add tests for the ARM MPTimer, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 13/32] tests: ptimer: Add tests for "no immediate trigger" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 02/32] exec.c: Remove static allocation of sub_section of sub_page, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 28/32] hw/arm: QOM'ify pxa2xx_gpio.c, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 08/32] hw/ptimer: Add "wraparound after one period" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 05/32] migration/savevm.c: migrate non-default page size, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 19/32] tests: ptimer: Replace 10000 with 1, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 17/32] tests: ptimer: Add tests for "no counter round down" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 15/32] tests: ptimer: Add tests for "no immediate reload" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 32/32] i2c: Add asserts for second smbus i2c_start_transfer(),
Peter Maydell <=
- [Qemu-devel] [PULL 09/32] tests: ptimer: Add tests for "wraparound after one period" policy, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 04/32] cpu: Support a target CPU having a variable page size, Peter Maydell, 2016/10/24
- [Qemu-devel] [PULL 03/32] translate-all.c: Compute L1 page table properties at runtime, Peter Maydell, 2016/10/24
- Re: [Qemu-devel] [PULL 00/32] target-arm queue, no-reply, 2016/10/24
- Re: [Qemu-devel] [PULL 00/32] target-arm queue, Peter Maydell, 2016/10/25