From patchwork Fri Dec 14 11:34:30 2012 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: 206395 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 59D1C2C008A for ; Fri, 14 Dec 2012 22:45:04 +1100 (EST) Received: from localhost ([::1]:59388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjThO-0001PS-Do for incoming@patchwork.ozlabs.org; Fri, 14 Dec 2012 06:45:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjThA-0001NM-2o for qemu-devel@nongnu.org; Fri, 14 Dec 2012 06:44:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TjTXj-0007Zv-2U for qemu-devel@nongnu.org; Fri, 14 Dec 2012 06:35:07 -0500 Received: from mout.web.de ([212.227.17.12]:61403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjTXi-0007ZB-MY for qemu-devel@nongnu.org; Fri, 14 Dec 2012 06:35:02 -0500 Received: from localhost.localdomain ([84.148.45.228]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0MHY5w-1TiMXk18Oa-003OKE; Fri, 14 Dec 2012 12:34:48 +0100 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Fri, 14 Dec 2012 12:34:30 +0100 Message-Id: <1355484872-11283-6-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355484872-11283-1-git-send-email-andreas.faerber@web.de> References: <1355484872-11283-1-git-send-email-andreas.faerber@web.de> MIME-Version: 1.0 X-Provags-ID: V02:K0:CX6KW6YwgCLqZnaRQ2nKHej2bHw8Axzu1HHSo2Hh1kf gLm1GsFPOH2MKF95jPyP78ykDLkcVlB8xfP3E8LWVPMxC9zR2g 1M50oKwnh759BLbX4Yv+348B5azHR8OmFV8MrNKPanlaywmY4k iMp+C1jckCRImd2F3/tTnPXgyPMeIy9jUClD9Hp8Lj5QmZ6VkL YxWa0Za6BDLQIlUj8ETFQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.12 Cc: Peter Maydell , Blue Swirl , Alex Horn , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH v2 5/7] 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 --- 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 9c67e64..ff9f28b 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); }