Received: from eggs.gnu.org ([2001:4830:134:3::10]:55223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bygFD-00055F-0O for qemu-devel@nongnu.org; Mon, 24 Oct 2016 10:28:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bygF9-0005HG-RU for qemu-devel@nongnu.org; Mon, 24 Oct 2016 10:28:55 -0400 Received: from mail-oi0-x241.google.com ([2607:f8b0:4003:c06::241]:34815) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bygF9-0005Gz-KM for qemu-devel@nongnu.org; Mon, 24 Oct 2016 10:28:51 -0400 Received: by mail-oi0-x241.google.com with SMTP id p136so2184742oic.1 for ; Mon, 24 Oct 2016 07:28:51 -0700 (PDT) Sender: Corey Minyard Reply-To: minyard@acm.org References: <1470153614-6657-1-git-send-email-minyard@acm.org> <76e1ee36-4e63-b22d-d41f-52d8ecfe3e14@acm.org> From: Corey Minyard Message-ID: <74e5cd6f-b5dd-7c1d-60db-56074fddef5b@acm.org> Date: Mon, 24 Oct 2016 09:28:47 -0500 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] i2c: Fix SMBus read transactions to avoid double events List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Corey Minyard , Kwon , Peter Crosthwaite , QEMU Developers , Alistair Francis , KONRAD Frederic On 10/24/2016 09:14 AM, Peter Maydell wrote: > On 23 October 2016 at 22:38, Corey Minyard wrote: >> On 10/22/2016 04:20 AM, Peter Maydell wrote: >>>>> I got here because Coverity complains that the >>>>> i2c_start_transfer() calls in smbus.c don't check their >>>>> return value. That suggests to me that we'd be better off >>>>> having a different function (i2c_restart_transfer() ??) >>>>> for the "I know we already did this once, so don't try to >>>>> re-determine who to send this to" case, rather than trying to >>>>> handle both cases in the same function. >>>> >>>> Perhaps so. Or maybe i2c_continue_transfer(). That would >>>> be more clear. The second operation can't fail, but relying >>>> on that is frail. >>> i2c_continue_transfer() sounds like a better name, yes. >>> Would you like to write a patch that takes that approach? >>> If you cc me I'll review it and put it through the >>> target-arm tree. >> >> I was working on this and looking at old information, and realized that >> this won't work. The same problem exists in I2C devices when >> doing SMBus emulation, the device driver in the OS will cause a >> i2c_start_transfer() to be done twice without an intervening >> i2c_end_transfer(). Though a continue function would fix the smbus >> case, it won't fix the i2c case. >> >> I can't think of a better way to do it than I have done. > OK, thanks for looking into this. I'll apply this patch to > target-arm.next, and we can think about something else for > the coverity issue. (Perhaps just assert() that i2c_start_transfer() > returns success? The bus contents shouldn't be able to change > I think...) An assert should work fine, you are right, the bus list can't change for the second call. I'll do a patch and some tests to be sure. -corey