Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3604745pxv; Mon, 5 Jul 2021 01:04:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvMTjxyKoctiCtnuZbki8xlfkhIjh7+EcESpAI7KjOZoHzv0EDg8WMnAWSV48BBKcop9gz X-Received: by 2002:a05:6402:524d:: with SMTP id t13mr14771831edd.303.1625472249802; Mon, 05 Jul 2021 01:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625472249; cv=none; d=google.com; s=arc-20160816; b=bY//ymeG/5a/s1+TVprcj6dWY8do5pEYP3DPwiw3LiM45PgOOXhS109BaqyZ5aV+u0 xJCn5EUv0HRa1Swu0Q/Bd221VC6qbrjGJ96W/Ha9/5ndIbb5zlr3HwPhIcUShXgyTwMk c9ngzf/FgaRthYpyEkcSd+EvgcU0UeJy9qENvciw3klHSaPlyOcq63vXJSiUihCr/qrp lSR3l7Vid4OUoVmeFvEaWLWzJs+S0Gpwljt7+qdBBVLiMHkSnSMJi/f/RMqhSGnOFy4X s3YH+0AFvVZKQap+kLBDw9cJ27SuFNXEt9cPZzqqO1MdkXnaXM53pj4LztWJDTPJvT2k NDQw== 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=7HFtrvl8Hp3RAM/FFfn+6kiIZNa9TUM0Rjxm9S07BYU=; b=DEz3jDdzCeJOMtCT/Rhs+GTxQqUjLQC8/66Lc/AuI0JFbfNufntK7hNaEs5jeaEvNC MSI93umaInsOSPju06AH8Ep2teEfew1vlG5tY6iYjjj4qVgbY0xJ+Evay/7YRKkshVTc qMo5BJXG23WI3mkn3DyvQMzw47WZjQNm1cKajJwxdKynG+lAnTCWCOZhAl761hsYyV2V 2IpRRS+8Q56ZZt7aj/VUVR817C0XbhxCdS2HkQosNh045MLshtOug2lp9V7po2vqIRRg buWx3yYio2pWAZyP8MBiqtewesR87EhziXtOV1HvbuIOZiSB8VS1pUx0L8h3348c8TZe xUgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wT20aR19; 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 di7si3140983ejc.275.2021.07.05.01.03.46; Mon, 05 Jul 2021 01:04:09 -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=wT20aR19; 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 S230053AbhGEIFZ (ORCPT + 99 others); Mon, 5 Jul 2021 04:05:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbhGEIFZ (ORCPT ); Mon, 5 Jul 2021 04:05:25 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1EB4C061760 for ; Mon, 5 Jul 2021 01:02:47 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id cs1-20020a17090af501b0290170856e1a8aso14334350pjb.3 for ; Mon, 05 Jul 2021 01:02:47 -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=7HFtrvl8Hp3RAM/FFfn+6kiIZNa9TUM0Rjxm9S07BYU=; b=wT20aR19P0l8+aXdUbQcBT2ncbwV7FLfcH5+V03YDNNqKv6/W87Yd4qmTk6DrcK30g DvdQhRcrJe9G3BFaoFV5p4WrmgUYKk3+u3X4UvHFL0rNEX3TkXe2iLY38CprPo955Xzk jXw1t1JN2FhA8XTxNXav8VU91f4SYPjClLB2etFbnaARMLCB1puhJz8RBotc77tIGNYG YqVZkWZTcmUltC94eZPNzm9ddh9ayqP2+UMdqYc/uXD+lDCeqntSEOoRDnRI80vOfihc 4Rwft7IiiyvdBJHDpT7OmrenOGha/+t3Zh7rTwhzsLC3HMMBQmC6moV+GZbSHYxhWGsY 5KAQ== 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=7HFtrvl8Hp3RAM/FFfn+6kiIZNa9TUM0Rjxm9S07BYU=; b=Fks5B5K5cx0VbQE7oYpFH08nrA7cUXBYFFSIJb5l/W9UdtDfXoKAxuEHLp0MYJ9G5h p5yDFb3/wxE+a1IC8N5PK1IQEZw9CGXQxKQZ8RaN1GsJXatNccpRwp+gSMixuRJSrC/d gXadcjsmCqk99vk9XOAUm/7oRABHOKh+mwjJUfYMQOxl/oyxyqMJ7NDCFjHLJ8XnFFaD wOlg+HDC9XaIRkYA6IGYfH7J0slbywJOOFjkbsAYbyY/qt9JrfnDtcxuKql/r5wK3PcP TzpzXENAlygA0cIZSuIRoNb7sNqgCA+i+RcFbFT2H2Ouad5YELJjvzcnu7RUzJYNE/Ms zH5Q== X-Gm-Message-State: AOAM533Gj3K4usSE+55SeGjwoAmdQ7bhMYsRZDtNcL/VsESt8pU9CV1M 7pgWqyNb/H99Nze4W3VrnSo0uA== X-Received: by 2002:a17:902:e848:b029:129:2e87:9944 with SMTP id t8-20020a170902e848b02901292e879944mr11397658plg.27.1625472167343; Mon, 05 Jul 2021 01:02:47 -0700 (PDT) Received: from localhost ([106.201.108.2]) by smtp.gmail.com with ESMTPSA id v14sm13323329pgo.89.2021.07.05.01.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 01:02:46 -0700 (PDT) Date: Mon, 5 Jul 2021 13:32:45 +0530 From: Viresh Kumar To: Jie Deng 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, andriy.shevchenko@linux.intel.com, yu1.wang@intel.com, shuo.a.liu@intel.com, conghui.chen@intel.com, stefanha@redhat.com, gregkh@linuxfoundation.org Subject: Re: [PATCH v13] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20210705080245.yabjlrgje5l7vndt@vireshk-i7> References: <8908f35a741e25a630d521e1012494e67d31ea64.1625466616.git.jie.deng@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8908f35a741e25a630d521e1012494e67d31ea64.1625466616.git.jie.deng@intel.com> User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jie. On 05-07-21, 14:53, Jie Deng wrote: > diff --git a/drivers/i2c/busses/i2c-virtio.c b/drivers/i2c/busses/i2c-virtio.c > +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; > + 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); Calling this for cases where virtio_i2c_prepare_reqs() itself has failed will always return NULL, should we even try to call this then ? virtqueue_get_buf() returns the next used buffer only, i.e. returned by the host ? > + > + /* > + * 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])) || Mentioning again for completeness of the review, reqs[i] can never be NULL here though req can be. And even in that case you never need to check req here. Feel free to ignore it if you want, we can always send a fixup patch later and discuss it further :) > + (req->in_hdr.status != VIRTIO_I2C_MSG_OK))) > + failed = true; > + > + i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], !failed); > + if (!failed) > + j++; > + } > + > + return fail ? 0 : j; Since you don't return ETIMEDOUT anymore, you can simply return j now. And so we can work with a single failed argument and don't need both fail and failed. > +} > + > +static int virtio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) > +{ > + struct virtio_i2c *vi = i2c_get_adapdata(adap); > + struct virtqueue *vq = vi->vq; > + struct virtio_i2c_req *reqs; > + unsigned long time_left; > + int ret; > + > + reqs = kcalloc(num, sizeof(*reqs), GFP_KERNEL); > + if (!reqs) > + return -ENOMEM; > + > + ret = virtio_i2c_prepare_reqs(vq, reqs, msgs, num); > + if (ret != num) { > + ret = virtio_i2c_complete_reqs(vq, reqs, msgs, ret, true); > + goto err_free; > + } > + > + reinit_completion(&vi->completion); > + virtqueue_kick(vq); > + time_left = wait_for_completion_timeout(&vi->completion, adap->timeout); > + ret = virtio_i2c_complete_reqs(vq, reqs, msgs, num, !time_left); > + > + if (!time_left) { > + ret = -ETIMEDOUT; > + dev_err(&adap->dev, "virtio i2c backend timeout.\n"); > + } > + > +err_free: > + kfree(reqs); > + return ret; > +} > diff --git a/include/uapi/linux/virtio_i2c.h b/include/uapi/linux/virtio_i2c.h > new file mode 100644 > index 0000000..df936a2 > --- /dev/null > +++ b/include/uapi/linux/virtio_i2c.h > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later WITH Linux-syscall-note */ > +/* > + * Definitions for virtio I2C Adpter > + * > + * Copyright (c) 2021 Intel Corporation. All rights reserved. > + */ > + > +#ifndef _UAPI_LINUX_VIRTIO_I2C_H > +#define _UAPI_LINUX_VIRTIO_I2C_H > + > +#include > +#include Both of these need to be the uapi headers as Andy said earlier and they better be in alphabetical order. #include #include Though in your support, I do see a lot of files in uapi/linux using the standard types.h, which looks wrong as that types.h is not a userspace ABI. -- viresh