Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3446598pxv; Sun, 4 Jul 2021 19:46:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKaBBPPg7jRFqiZFmtHdk7TwQSnxMHJVyYcrAVPWgIJ7ebAS+I2yrETE76vx/F4SgkUILG X-Received: by 2002:a17:906:7012:: with SMTP id n18mr11302163ejj.236.1625453188139; Sun, 04 Jul 2021 19:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625453188; cv=none; d=google.com; s=arc-20160816; b=u9Rp5InXkd+lB/xyil7p6jq9195QLlALPuUD4DFnuEWuatH2UppnnsJfwljy9xrybm 1uUaNd62nt/1wKRpdb/MUY1KE2rXO+tH1Qt5tPyJX1PVV3abKDOjBr1QANuC8QNIsoNw d3ieUY2LDuKgTMKKIXzh3RF5IT32rHHPyJy3wHdoPrC0AMZKZY1L47sCyJgaptlCY6r9 4eQo7kgG5YzZZcVp1VE42GEva2HpXUzf9WmNcY9bbM7Dge6AMBKMsqa+tEBKsukuvOrM IrO0icJt3pdiquoE0QmG3hiBtUcwkOFIeHgoyLktgdQ6bT/k8G1i+LqFuI0zgD6Uaosw 2ePg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=xuSwe/RfSoZsmqWmRxSCKHgdBKSJxFIJ1HP2k67JkNE=; b=pJ8Y2Zwe/ORUuc5pS7tjvuJ//38329JDTxQHtl3mrypNMuETIVMFfItkJxDO0FN2tt zSTP2mJUWOgWzPzhlFyZZuXijZ23LsepjChEQV6KC13BxBGbQFjOqyrsNinaeE72ml2U 5jdJYxvItSuOm0JSY77fZgYRZC/z2gln9KW7q4VppAol0rcKGVE+oVo/V3eQWxKWumwU qcFhL65ffHw2UKgmMXr9Hpt07Chb7R2DHs4N18USlikSk/9vOnTkZM5cABibRbUmbD9A 8roJ7e3m6rmTHElaBKZhElmpF5CcXnS8pPlw9oFx6D5N/2CwTNY6jK6XcWQFKl7BNmi7 tDlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TLV4gOuF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gz1si10933587ejc.700.2021.07.04.19.46.05; Sun, 04 Jul 2021 19:46:28 -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; dkim=pass header.i=@linaro.org header.s=google header.b=TLV4gOuF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbhGECqU (ORCPT + 99 others); Sun, 4 Jul 2021 22:46:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbhGECqU (ORCPT ); Sun, 4 Jul 2021 22:46:20 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 461B4C061574 for ; Sun, 4 Jul 2021 19:43:43 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id o18so16321340pgu.10 for ; Sun, 04 Jul 2021 19:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xuSwe/RfSoZsmqWmRxSCKHgdBKSJxFIJ1HP2k67JkNE=; b=TLV4gOuFn+VPLM41B7YR5L1wKfxLzcF6bpswN35lacqXklwXMThcUo1B9UxFGWGPbc 6PBWQHbzjUGYKZ4JQhq1j45l5gCQTgzTlmgp5zMxaCGufDbwT4VFfkCk5bl+oqhW97Ta HRAnqvXotEJYQ7QiirWsTDMvf6wLaXM0XnMGWZcVZcUj6S8YkdKEuKBzvpucQF5ZHLJ4 ZnDjDJKLK8jD2lgAz9H92+hFKOWObUF09q/ReTqmmbwTHHaaKBkkBPlY40wMnTHYpETJ m24o5HYwIKUPJz0kfdBUvF1aeIizRv8nbCZMwoJmD4y8bZAbDrmSb/tvRuiNfpb0wX3I V0VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xuSwe/RfSoZsmqWmRxSCKHgdBKSJxFIJ1HP2k67JkNE=; b=PHtiCeqPIbFZxhqNjPiIbZJpBK3+sEP+hPcxJbG9kti7zP4pgl1DAwT8cSfjBDlOLU 2xFeu3RroL6AGvUGRN7hFj1hvNEshTRYQJHOPNfbPIvyg/1KdyNAaHUlSgmLb9uJPP3T 0dItWDTRhb0JIhouRjksOvjcQBJqR6bhUkASOrO1udoIe/oVyHOvAK7Ge18F1FsfWpYS kXR1UucmnD8mbv+8Q/apThUcfNE1BvQt5w71MXhYbdqFMay3RXVh2JLOBTzRuwal4CQZ IRhvttDlowQ8bSf63bvF5rAnrtdS2PgLy5VMpznSHQgt8slXn91s/767tWo8SYSp6TrJ qpwQ== X-Gm-Message-State: AOAM530IMIRDf+yswhwfnFuSbslKtulc9zFMfbbSkvJtIXJ7Ywsqq3cw c3wHijM02+RWd/M/AIt35BUMTg== X-Received: by 2002:a63:284:: with SMTP id 126mr13154170pgc.347.1625453022687; Sun, 04 Jul 2021 19:43:42 -0700 (PDT) Received: from localhost ([106.201.108.2]) by smtp.gmail.com with ESMTPSA id y127sm5987540pfg.96.2021.07.04.19.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 19:43:42 -0700 (PDT) Date: Mon, 5 Jul 2021 08:13:40 +0530 From: Viresh Kumar To: Andy Shevchenko Cc: Jie Deng , 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 Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20210705024340.mb5sv5epxbdatgsg@vireshk-i7> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > + 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. > > > +} -- viresh