Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3552360pxv; Sun, 4 Jul 2021 23:25:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMWjtniMiVdmo5ysMbiGMGHYfQhgBuJAtv6c0GOq+YUJr22AD90lW1pc7rVFCnuHztJu5e X-Received: by 2002:a05:6402:520c:: with SMTP id s12mr14706746edd.357.1625466333868; Sun, 04 Jul 2021 23:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625466333; cv=none; d=google.com; s=arc-20160816; b=KrPRvA3r0tKIfUh1JZZpJXo55Oq703rsLQLvSMAdmAqZCVcfUDxD/JBjXydB2sFE7+ IwyepvN8wlN4ZzbWUbe2pZ6UBsiG24tRzgUgBn5qIwv++N6GY7jP2Wiw6Gkm5HUppnJl 40vyXVH1swjFwXJoSW8IAr+c81sQZIt9iqwynA9MMQGBaho2sjfnm5Hd+lALqQ6Qe/Te ZPbGzkOQmKUngA2cV8FpbV+jnIOdURgqACv51vaPppLoEns7zKRlQfpNxrWJC0YMjVkK ctAZ3UP6vLl2g5DZcWqyujwuJOcOrvuXP5xd15PxNorxtbll6cm02/iCvsE81tZLSmjx 5vHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=E59sdAnqEASQjyGV4gOZ608iiRfe4MjQLow4LjxVZIU=; b=UmgQOb1DVG1YPrh3ApxVX+Q7JbaQAuPfKDQjPM7jtlBJ8pjj5GY3m4j//fDp9aFRvD a5TquGo9MBM7BaKrFDIk2Ps3CvI8mzDRfLID2AkMON+ozUNl6KHqZ83O6iwT/4J/aJ/A 4DOqqQJ8e0TuhTDCums7blvmELvMZ4YAxtTnqVePpsT4hi29DPMiIgQ6fEcnOCpvmq27 v+9y+aIXoNma87HtHu2VCnhi4yaxL4Oh0Udg9DtzoHGLmye03p4RFr9pIBMzp9mfuQyX ojwMdzULUnhKlsi3Kpk+FvcNYQJdL1obvcawh3XLcTUUeW+4lW1fe8Cmz7RpSdjkdaO0 vPJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc33si3189765ejc.308.2021.07.04.23.25.10; Sun, 04 Jul 2021 23:25:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbhGEGYd (ORCPT + 99 others); Mon, 5 Jul 2021 02:24:33 -0400 Received: from mga17.intel.com ([192.55.52.151]:55416 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbhGEGYd (ORCPT ); Mon, 5 Jul 2021 02:24:33 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10035"; a="189308641" X-IronPort-AV: E=Sophos;i="5.83,325,1616482800"; d="scan'208";a="189308641" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2021 23:21:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,325,1616482800"; d="scan'208";a="562409078" Received: from dengjie-mobl1.ccr.corp.intel.com (HELO [10.239.154.58]) ([10.239.154.58]) by fmsmga001.fm.intel.com with ESMTP; 04 Jul 2021 23:21:53 -0700 Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver To: Viresh Kumar , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, wsa@kernel.org, wsa+renesas@sang-engineering.com, mst@redhat.com, arnd@arndb.de, jasowang@redhat.com, yu1.wang@intel.com, shuo.a.liu@intel.com, conghui.chen@intel.com, stefanha@redhat.com References: <20210705024340.mb5sv5epxbdatgsg@vireshk-i7> From: Jie Deng Message-ID: Date: Mon, 5 Jul 2021 14:21:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210705024340.mb5sv5epxbdatgsg@vireshk-i7> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/7/5 10:43, Viresh Kumar wrote: > On 02-07-21, 12:58, Andy Shevchenko wrote: >> On Fri, Jul 02, 2021 at 04:46:47PM +0800, Jie Deng wrote: >>> +static int virtio_i2c_complete_reqs(struct virtqueue *vq, >>> + struct virtio_i2c_req *reqs, >>> + struct i2c_msg *msgs, int nr, >>> + bool fail) >>> +{ >>> + struct virtio_i2c_req *req; >>> + bool failed = fail; > Jie, you can actually get rid of this variable too. Jut rename fail to failed > and everything shall work as you want. Oh, You are not right. I just found we can't remove this variable. The "fail" and "failed" have different meanings for this function. We need fail to return the result. >>> + unsigned int len; >>> + int i, j = 0; >>> + >>> + for (i = 0; i < nr; i++) { >>> + /* Detach the ith request from the vq */ >>> + req = virtqueue_get_buf(vq, &len); >>> + >>> + /* >>> + * Condition (req && req == &reqs[i]) should always meet since >>> + * we have total nr requests in the vq. >>> + */ >>> + if (!failed && (WARN_ON(!(req && req == &reqs[i])) || >>> + (req->in_hdr.status != VIRTIO_I2C_MSG_OK))) >>> + failed = true; >> ...and after failed is true, we are continuing the loop, why? > Actually this function can be called with fail set to true. We proceed as we > need to call i2c_put_dma_safe_msg_buf() for all buffers we allocated earlier. > >>> + i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], !failed); >>> + if (!failed) >>> + ++j; >> Besides better to read j++ the j itself can be renamed to something more >> verbose. >> >>> + } >>> + return (fail ? -ETIMEDOUT : j); >> Redundant parentheses. >> >>> +}