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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 9247CC11F68 for ; Fri, 2 Jul 2021 09:58:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CA9B613BC for ; Fri, 2 Jul 2021 09:58:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231330AbhGBKA7 (ORCPT ); Fri, 2 Jul 2021 06:00:59 -0400 Received: from mga06.intel.com ([134.134.136.31]:44767 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbhGBKA6 (ORCPT ); Fri, 2 Jul 2021 06:00:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="269835890" X-IronPort-AV: E=Sophos;i="5.83,316,1616482800"; d="scan'208";a="269835890" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 02:58:26 -0700 X-IronPort-AV: E=Sophos;i="5.83,316,1616482800"; d="scan'208";a="558990539" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 02:58:23 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1lzFwA-007eal-2Q; Fri, 02 Jul 2021 12:58:18 +0300 Date: Fri, 2 Jul 2021 12:58:18 +0300 From: Andy Shevchenko 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, yu1.wang@intel.com, shuo.a.liu@intel.com, conghui.chen@intel.com, viresh.kumar@linaro.org, stefanha@redhat.com Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On Fri, Jul 02, 2021 at 04:46:47PM +0800, Jie Deng wrote: > Add an I2C bus driver for virtio para-virtualization. > > The controller can be emulated by the backend driver in > any device model software by following the virtio protocol. > > The device specification can be found on > https://lists.oasis-open.org/archives/virtio-comment/202101/msg00008.html. > > By following the specification, people may implement different > backend drivers to emulate different controllers according to > their needs. ... > +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); > + > + /* > + * 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? > + 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. > +} ... > + ret = virtio_i2c_send_reqs(vq, reqs, msgs, num); > + if (ret != num) { > + virtio_i2c_complete_reqs(vq, reqs, msgs, ret, true); Below you check the returned code, here is not. > + ret = 0; > + goto err_free; > + } > + > + reinit_completion(&vi->completion); > + virtqueue_kick(vq); > + > + time_left = wait_for_completion_timeout(&vi->completion, adap->timeout); > + if (!time_left) > + dev_err(&adap->dev, "virtio i2c backend timeout.\n"); > + > + ret = virtio_i2c_complete_reqs(vq, reqs, msgs, num, !time_left); > + > +err_free: > + kfree(reqs); > + return ret; > +++ b/include/uapi/linux/virtio_i2c.h > +#include > + > +/* The bit 0 of the @virtio_i2c_out_hdr.@flags, used to group the requests */ > +#define VIRTIO_I2C_FLAGS_FAIL_NEXT BIT(0) It's _BITUL() or so from linux/const.h. https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/const.h#L28 You may not use internal definitions in UAPI headers. -- With Best Regards, Andy Shevchenko 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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 39831C11F68 for ; Fri, 2 Jul 2021 09:58:37 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85A0E6140E for ; Fri, 2 Jul 2021 09:58:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85A0E6140E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4BE6F83C34; Fri, 2 Jul 2021 09:58:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DR39FfVuxDfZ; Fri, 2 Jul 2021 09:58:34 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id BEDCC83C1C; Fri, 2 Jul 2021 09:58:33 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A18F4C0010; Fri, 2 Jul 2021 09:58:33 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id F1511C000E for ; Fri, 2 Jul 2021 09:58:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D75CB401C6 for ; Fri, 2 Jul 2021 09:58:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KGYAeXcd8lxM for ; Fri, 2 Jul 2021 09:58:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by smtp2.osuosl.org (Postfix) with ESMTPS id 9C3B24018B for ; Fri, 2 Jul 2021 09:58:30 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="230377674" X-IronPort-AV: E=Sophos;i="5.83,316,1616482800"; d="scan'208";a="230377674" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 02:58:26 -0700 X-IronPort-AV: E=Sophos;i="5.83,316,1616482800"; d="scan'208";a="558990539" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 02:58:23 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1lzFwA-007eal-2Q; Fri, 02 Jul 2021 12:58:18 +0300 Date: Fri, 2 Jul 2021 12:58:18 +0300 From: Andy Shevchenko To: Jie Deng Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Cc: yu1.wang@intel.com, arnd@arndb.de, mst@redhat.com, viresh.kumar@linaro.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, wsa@kernel.org, wsa+renesas@sang-engineering.com, linux-i2c@vger.kernel.org, stefanha@redhat.com, shuo.a.liu@intel.com, conghui.chen@intel.com X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Fri, Jul 02, 2021 at 04:46:47PM +0800, Jie Deng wrote: > Add an I2C bus driver for virtio para-virtualization. > > The controller can be emulated by the backend driver in > any device model software by following the virtio protocol. > > The device specification can be found on > https://lists.oasis-open.org/archives/virtio-comment/202101/msg00008.html. > > By following the specification, people may implement different > backend drivers to emulate different controllers according to > their needs. ... > +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); > + > + /* > + * 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? > + 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. > +} ... > + ret = virtio_i2c_send_reqs(vq, reqs, msgs, num); > + if (ret != num) { > + virtio_i2c_complete_reqs(vq, reqs, msgs, ret, true); Below you check the returned code, here is not. > + ret = 0; > + goto err_free; > + } > + > + reinit_completion(&vi->completion); > + virtqueue_kick(vq); > + > + time_left = wait_for_completion_timeout(&vi->completion, adap->timeout); > + if (!time_left) > + dev_err(&adap->dev, "virtio i2c backend timeout.\n"); > + > + ret = virtio_i2c_complete_reqs(vq, reqs, msgs, num, !time_left); > + > +err_free: > + kfree(reqs); > + return ret; > +++ b/include/uapi/linux/virtio_i2c.h > +#include > + > +/* The bit 0 of the @virtio_i2c_out_hdr.@flags, used to group the requests */ > +#define VIRTIO_I2C_FLAGS_FAIL_NEXT BIT(0) It's _BITUL() or so from linux/const.h. https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/const.h#L28 You may not use internal definitions in UAPI headers. -- With Best Regards, Andy Shevchenko _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization