fix I2C slave addressing
authorJuha Riihimäki <Juha.Riihimaki@nokia.com>
Mon, 8 Jun 2009 06:27:19 +0000 (09:27 +0300)
committerAurelien Jarno <aurelien@aurel32.net>
Wed, 2 Dec 2009 16:26:19 +0000 (17:26 +0100)
With the recent device handling changes the I2C slave addressing code
was broken. With current code, if a slave with the correct address is

not found on the bus the last scanned slave on the bus will be
addressed. This is wrong. Please find attached a patch to fix it.

Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
Acked-by: Riku Voipio <riku.voipio@iki.fi>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
hw/i2c.c

index 5c291ce0a9e92d8b37e61376e3ea6959af59b901..bee8e88c6bc38351de754c53005928b371e881d5 100644 (file)
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -85,9 +85,11 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
     i2c_slave *slave = NULL;
 
     QLIST_FOREACH(qdev, &bus->qbus.children, sibling) {
-        slave = I2C_SLAVE_FROM_QDEV(qdev);
-        if (slave->address == address)
+        i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
+        if (candidate->address == address) {
+            slave = candidate;
             break;
+        }
     }
 
     if (!slave)