From patchwork Mon Oct 24 15:10:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 9392397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E7E660762 for ; Mon, 24 Oct 2016 15:47:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 903F329173 for ; Mon, 24 Oct 2016 15:47:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8498529177; Mon, 24 Oct 2016 15:47:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1D4329173 for ; Mon, 24 Oct 2016 15:47:18 +0000 (UTC) Received: from localhost ([::1]:47594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byhT4-0005KN-8z for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Oct 2016 11:47:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bygu5-0007P4-FC for qemu-devel@nongnu.org; Mon, 24 Oct 2016 11:11:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bygu0-00037B-TC for qemu-devel@nongnu.org; Mon, 24 Oct 2016 11:11:09 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:36354) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bygu0-00036c-Kb for qemu-devel@nongnu.org; Mon, 24 Oct 2016 11:11:04 -0400 Received: by mail-pf0-x244.google.com with SMTP id r16so16818454pfg.3 for ; Mon, 24 Oct 2016 08:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=gW0FLqla1BA9iBeOjJtrYOAhtBNBGy51j3vN/gXWOzA=; b=Ox2HJk9niIamV6dvofxkeBGt2ZSr0lTZwG8jAC9girg6dfXEWMlSYSa4VmhQs5t4HA nRgXAp17wN431QnhnpgYobFV0dUaL4mpMNgtCTIQZQlzVd1GLPXOogUhZK2hWobfYNQ9 BbuSFTEZst/APm9YXy73rvh5mcpxIxyIFLywgqVngJ4txl1ISuzjvXZFPQ+HBsaB763+ ONAlW+l76Xwt8cPFBWmzfVyO7O4vrgaYKrH9jc4JsPRv782kGiBHCYSQBcI7k1PJtGtq +dhV1LxKX2zSI52gCNoVDqrUb1Oe7q4qNYJV4X/2ZCx0R3JMwk5S2gaMDJg9DiYlqsOM offQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=gW0FLqla1BA9iBeOjJtrYOAhtBNBGy51j3vN/gXWOzA=; b=jrRYVXQZUprGTE4g875SEtoGAsdkTTWiojoouGRKk5X0G8m5810N4HutDaaKYTWEmV wizpOMbL25U0aD8HQEuRHsPxzMCwELjY5awl8Nk4U8giLhEruBOLul6bViUo2CRgogME vw+tljawC3rt0xGVg1FWAzwG0nVKjii+zEZrO1Bwxb7rocIOnaBhMdyZg93xygPwVaN7 5N498bhS7Cqj3R5yzQ6/K8iksQAxeCFdh4ZqRXUqP1ldDc+3Qkkevx9BBdF5rAtBxZvt W0H2n7fmUMrnGvYhWZ/Q43Wx5F6Z+Z9l1BhE2CFfyNiGpoAsr+MB75wB1zrZZuFSyXIm NOfg== X-Gm-Message-State: ABUngvdOywsE4njToitTT5QBG/Vq5e9PwavvpXifftf6he/ft9jxO2P8ojA/IP8P5aapvA== X-Received: by 10.99.149.6 with SMTP id p6mr24725920pgd.21.1477321862913; Mon, 24 Oct 2016 08:11:02 -0700 (PDT) Received: from serve.minyard.net ([47.184.183.230]) by smtp.gmail.com with ESMTPSA id o184sm26232762pfg.73.2016.10.24.08.11.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 08:11:02 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:785f:c781:63d2:a774]) by serve.minyard.net (Postfix) with ESMTPA id 0B5809F5; Mon, 24 Oct 2016 10:10:58 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 3D3F2300070; Mon, 24 Oct 2016 10:10:56 -0500 (CDT) From: minyard@acm.org To: Peter Maydell Date: Mon, 24 Oct 2016 10:10:54 -0500 Message-Id: <1477321854-8080-1-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH] i2c: Add asserts for second smbus i2c_start_transfer() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , KONRAD Frederic , QEMU Developers , Alistair Francis Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard 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 --- hw/i2c/core.c | 5 ++++- hw/i2c/smbus.c | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) I tested this with the IPMI SMbus driver for a while. diff --git a/hw/i2c/core.c b/hw/i2c/core.c index bd8f167..b9dea79 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -88,7 +88,10 @@ 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..bf46d22 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus.c @@ -248,7 +248,7 @@ int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command) return -1; } i2c_send(bus, command); - i2c_start_transfer(bus, addr, 1); + assert(!i2c_start_transfer(bus, addr, 1)); data = i2c_recv(bus); i2c_nack(bus); i2c_end_transfer(bus); @@ -273,7 +273,7 @@ int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command) return -1; } i2c_send(bus, command); - i2c_start_transfer(bus, addr, 1); + assert(!i2c_start_transfer(bus, addr, 1)); data = i2c_recv(bus); data |= i2c_recv(bus) << 8; i2c_nack(bus); @@ -302,7 +302,7 @@ 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); + assert(!i2c_start_transfer(bus, addr, 1)); len = i2c_recv(bus); if (len > 32) { len = 0;