Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MDYL1-000860-UM for qemu-devel@nongnu.org; Mon, 08 Jun 2009 02:28:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MDYKv-0007xP-MX for qemu-devel@nongnu.org; Mon, 08 Jun 2009 02:28:06 -0400 Received: from [199.232.76.173] (port=35025 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MDYKv-0007x3-Hp for qemu-devel@nongnu.org; Mon, 08 Jun 2009 02:28:01 -0400 Received: from smtp.nokia.com ([192.100.105.134]:34689 helo=mgw-mx09.nokia.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MDYKv-0002Wj-0p for qemu-devel@nongnu.org; Mon, 08 Jun 2009 02:28:01 -0400 Received: from esebh106.NOE.Nokia.com (esebh106.ntc.nokia.com [172.21.138.213]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id n586RlHc012903 for ; Mon, 8 Jun 2009 01:27:53 -0500 Received: from esdhcp043194.research.nokia.com (esdhcp043194.research.nokia.com [172.21.43.194]) by mgw-da02.ext.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id n586RDKd020477 for ; Mon, 8 Jun 2009 09:27:15 +0300 Message-Id: From: =?ISO-8859-1?Q?Juha_Riihim=E4ki?= Content-Type: multipart/mixed; boundary=Apple-Mail-2--152732365 Mime-Version: 1.0 (Apple Message framework v935.3) Date: Mon, 8 Jun 2009 09:27:19 +0300 Subject: [Qemu-devel] [PATCH] fix I2C slave addressing List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --Apple-Mail-2--152732365 Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable With the recent device handling changes the I2C slave addressing code =20= was broken. With current code, if a slave with the correct address is =20= not found on the bus the last scanned slave on the bus will be =20 addressed. This is wrong. Please find attached a patch to fix it. Signed-off-by: Juha Riihim=E4ki --- diff --git a/hw/i2c.c b/hw/i2c.c index 8a0c4d7..e1dacef 100644 --- a/hw/i2c.c +++ b/hw/i2c.c @@ -69,9 +69,11 @@ int i2c_start_transfer(i2c_bus *bus, int address, =20 int recv) i2c_slave *slave =3D NULL; LIST_FOREACH(qdev, &bus->qbus.children, sibling) { - slave =3D I2C_SLAVE_FROM_QDEV(qdev); - if (slave->address =3D=3D address) + i2c_slave *candidate =3D I2C_SLAVE_FROM_QDEV(qdev); + if (candidate->address =3D=3D address) { + slave =3D candidate; break; + } } if (!slave) --Apple-Mail-2--152732365 Content-Disposition: attachment; filename=i2c.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="i2c.diff" Content-Transfer-Encoding: 7bit diff --git a/hw/i2c.c b/hw/i2c.c index 8a0c4d7..e1dacef 100644 --- a/hw/i2c.c +++ b/hw/i2c.c @@ -69,9 +69,11 @@ int i2c_start_transfer(i2c_bus *bus, int address, int recv) i2c_slave *slave = NULL; LIST_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) --Apple-Mail-2--152732365--