From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B219C07E99 for ; Mon, 5 Jul 2021 06:31:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DB15613DD for ; Mon, 5 Jul 2021 06:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229884AbhGEGdn (ORCPT ); Mon, 5 Jul 2021 02:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbhGEGdm (ORCPT ); Mon, 5 Jul 2021 02:33:42 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F14C061574 for ; Sun, 4 Jul 2021 23:31:06 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id v7so17385493pgl.2 for ; Sun, 04 Jul 2021 23:31:06 -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=wWMXmMCJoSZ9OCdipGCDRnC3WjS629PoEJ5rr2yZGV4=; b=DkNMSvM96dm/AcUPUGEq9JBeaCg2RBULAlZIqhkyanmq/ooofwovzz1sIYEjs873Hy hfEBAN6RtF0t5J86yneotbcmbmZzq0O3hj4ZljjxrqTM3IXpQJrnodt+Xb5GgW6QQe5p cIrHyv3lrAXb2qZ14efevI+sKddKGnFRJFyEpvM1+7pWINYIv2NA0Ce9O75/33njDL7i y99Glt8+3v+1ZCUoIR0bAnLi+lVKclqr98EkceNpSYW47BaMMJOf+0gM8qLTxP4qANrk 0EmPbLfPMNYyqnfq7aL56vC+OAJzTbQezhjtY0qK4Plk1T8ysZclL44NmcpHZloPEw66 ItJg== 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=wWMXmMCJoSZ9OCdipGCDRnC3WjS629PoEJ5rr2yZGV4=; b=JAV/+F28ZEX+FIXsL6mjZrH4MmnBwSYS+fHaD+hgxMs0voMsO7oCjYpdvCEV3tncgk sZH8xwaYO2MU6IEsT6zNAXCoM3n1JK37LHc12jOW9MZaWCc2VxjK2cuKAvIvk8Y6lfz5 lolSC/t78IkMBqI7BK7LCrc7wygRyhJCz7u43GcNbcNUO10xX546JKyerU7POCz2RdyZ jmgksdCwdsO1XSDwrpE1uk78hir0vTDjzdylxj5P8l+2pbbREh6keZke9Lr9yiSh9y1h ++bs2i9dk3EaWaoaYDukUFh1icNJElmWQyvsmENML52MHU+i7d++66AKsGL0zlvpGO34 DIMg== X-Gm-Message-State: AOAM530AoY7dfxIJZo2M/g3gl5ymr7/0DGABl2zOcZ5ehME/td6k5K6j qtrNFKdTJs5c7HTJWsjlGdZmjA== X-Google-Smtp-Source: ABdhPJwjbeDpEwUGHX4wapdtd68i1JUGbnqyQuUWmDrUGIl18KntYn+5LqFO42LZddC9cRK1RvizQQ== X-Received: by 2002:a63:5a5b:: with SMTP id k27mr1117953pgm.294.1625466665652; Sun, 04 Jul 2021 23:31:05 -0700 (PDT) Received: from localhost ([106.201.108.2]) by smtp.gmail.com with ESMTPSA id z20sm13337396pgk.36.2021.07.04.23.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 23:31:05 -0700 (PDT) Date: Mon, 5 Jul 2021 12:01:03 +0530 From: Viresh Kumar To: Jie Deng Cc: Andy Shevchenko , 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: <20210705063103.4gnrnx6qwheq37lp@vireshk-i7> References: <20210705024340.mb5sv5epxbdatgsg@vireshk-i7> 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 05-07-21, 14:21, Jie Deng wrote: > > 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. Ahh, yes. You are right. Maybe rename fail to timedout, it would make it more readable, else fail and failed look very similar. > > > > + 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