From patchwork Wed Jan 16 00:57:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 212370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1684A2C007C for ; Wed, 16 Jan 2013 12:33:31 +1100 (EST) Received: from localhost ([::1]:56673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvHLB-0005jN-5v for incoming@patchwork.ozlabs.org; Tue, 15 Jan 2013 19:58:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvHKU-0003xe-IP for qemu-devel@nongnu.org; Tue, 15 Jan 2013 19:58:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvHKT-0002SS-GB for qemu-devel@nongnu.org; Tue, 15 Jan 2013 19:58:10 -0500 Received: from mout.web.de ([212.227.17.11]:64223) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvHKT-0002SJ-6U for qemu-devel@nongnu.org; Tue, 15 Jan 2013 19:58:09 -0500 Received: from localhost.localdomain ([84.148.40.139]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0MNLRJ-1TsmDW3xgP-006fk4; Wed, 16 Jan 2013 01:58:08 +0100 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2013 01:57:56 +0100 Message-Id: <1358297879-26576-4-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358297879-26576-1-git-send-email-andreas.faerber@web.de> References: <1358297879-26576-1-git-send-email-andreas.faerber@web.de> MIME-Version: 1.0 X-Provags-ID: V02:K0:2qpIEjoIvEY/eJjtsZzBQiA2pk7q5DaPocgz9mFqSek QU8pom2XR4oHwZwTz3zX0bGh2TZNre6DIcQ56ffMrDwyZsL0cD axBsyKN9zzzKuy0HBWdJ8Or/ViIQCK035lCdazUIw7t5cJ0CDP 6gVkhm0FvxVbu7op4MOfo9+ZtTglh3mOHyLfcDQ0nyb/9nCBkZ 7V3TYkdITVkV5W1oKzVSw== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.11 Cc: Alex Horn , =?UTF-8?q?Andreas=20F=C3=A4rber?= , anthony@codemonkey.ws Subject: [Qemu-devel] [PATCH for-1.4 v4 3/6] tmp105: Fix I2C protocol bug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org An early length postincrement in the TMP105's I2C TX path led to transfers of more than one byte to place the second byte in the third byte's place within the buffer and the third byte to get discarded. Fix this by explictly incrementing the length after the checks but before the callback is called, which again checks the length. Adjust the Coding Style while at it. Signed-off-by: Alex Horn Signed-off-by: Andreas Färber Reviewed-by: Anthony Liguori --- hw/tmp105.c | 9 ++++++--- 1 Datei geändert, 6 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-) diff --git a/hw/tmp105.c b/hw/tmp105.c index 0ade4eb..10d94c9 100644 --- a/hw/tmp105.c +++ b/hw/tmp105.c @@ -153,11 +153,14 @@ static int tmp105_tx(I2CSlave *i2c, uint8_t data) { TMP105State *s = (TMP105State *) i2c; - if (!s->len ++) + if (s->len == 0) { s->pointer = data; - else { - if (s->len <= 2) + s->len++; + } else { + if (s->len <= 2) { s->buf[s->len - 1] = data; + } + s->len++; tmp105_write(s); }