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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,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 95872C07E98 for ; Mon, 5 Jul 2021 06:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BE96613D1 for ; Mon, 5 Jul 2021 06:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbhGEGZC (ORCPT ); Mon, 5 Jul 2021 02:25:02 -0400 Received: from mga07.intel.com ([134.134.136.100]:35169 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbhGEGZB (ORCPT ); Mon, 5 Jul 2021 02:25:01 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10035"; a="272779669" X-IronPort-AV: E=Sophos;i="5.83,325,1616482800"; d="scan'208";a="272779669" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2021 23:22:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,325,1616482800"; d="scan'208";a="562409136" 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:22:15 -0700 Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver To: Viresh Kumar 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 References: <20210705024056.ndth2bwn2itii5g3@vireshk-i7> <332af2be-0fb0-a846-8092-49d496fe8b6b@intel.com> <20210705043841.zujwo672nfdndpg2@vireshk-i7> From: Jie Deng Message-ID: <6aabc877-673a-e2bc-da2d-ec6741b4159b@intel.com> Date: Mon, 5 Jul 2021 14:22:15 +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: <20210705043841.zujwo672nfdndpg2@vireshk-i7> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On 2021/7/5 12:38, Viresh Kumar wrote: > On 05-07-21, 11:45, Jie Deng wrote: >> On 2021/7/5 10:40, Viresh Kumar wrote: >>> On 02-07-21, 16:46, Jie Deng wrote: >>> The right way of doing this is is making this function return - Error on failure >>> and 0 on success. There is no point returning number of successful additions >>> here. >> >> We need the number for virtio_i2c_complete_reqs to do cleanup. We don't have >> to >> >> do cleanup "num" times every time. Just do it as needed. > If you do full cleanup here, then you won't required that at the caller site. > >>> Moreover, on failures this needs to clean up (free the dmabufs) itself, just >>> like you did i2c_put_dma_safe_msg_buf() at the end. The caller shouldn't be >>> required to handle the error cases by freeing up resources. >> >> This function will return the number of requests being successfully prepared >> and make sure >> >> resources of the failed request being freed. And virtio_i2c_complete_reqs >> will free the >> >> resources of those successful request. > It just looks cleaner to give such responsibility to each and every function, > i.e. if they fail, they should clean stuff up instead of the caller. That's the > normal philosophy you will find across kernel in most of the cases. > >>>> + /* >>>> + * 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))) >>> What about writing this as: >>> >>> if (!failed && (WARN_ON(req != &reqs[i]) || >>> (req->in_hdr.status != VIRTIO_I2C_MSG_OK))) >>> >>> We don't need to check req here since if req is NULL, we will not do req->in_hdr >>> at all. >> >> It's right here just because the &reqs[i] will never be NULL in our case. >> But if you see >> >> "virtio_i2c_complete_reqs" as an independent function, you need to check the >> >> req. From the perspective of the callee, you can't ask the caller always >> give you >> >> the non-NULL parameters. > We need to keep this driver optimized in its current form. If you see your own > argument here, then why don't you test vq or msgs for a valid pointer ? And even > reqs. > > If we know for certain that this will never happen, then it should be optimized. > But if you see a case where reqs[i] can be NULL here, then it would be fine. > ot the driver. And we don't need to take care of that. This is still not enough to convince me.  So I won't change them for now until I see it is the consensus of the majority. Thank you. 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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,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 72E21C07E98 for ; Mon, 5 Jul 2021 06:22:24 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (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 262AF61375 for ; Mon, 5 Jul 2021 06:22:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 262AF61375 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=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 smtp4.osuosl.org (Postfix) with ESMTP id D9FB640462; Mon, 5 Jul 2021 06:22:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VAoDeV-iU1W9; Mon, 5 Jul 2021 06:22:22 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 47F6A40465; Mon, 5 Jul 2021 06:22:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 16B78C0010; Mon, 5 Jul 2021 06:22:22 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 002A4C000E for ; Mon, 5 Jul 2021 06:22:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id F042160796 for ; Mon, 5 Jul 2021 06:22:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X2FpfY1M5w7X for ; Mon, 5 Jul 2021 06:22:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by smtp3.osuosl.org (Postfix) with ESMTPS id 2752F605DD for ; Mon, 5 Jul 2021 06:22:20 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10035"; a="205921192" X-IronPort-AV: E=Sophos;i="5.83,325,1616482800"; d="scan'208";a="205921192" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2021 23:22:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,325,1616482800"; d="scan'208";a="562409136" 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:22:15 -0700 Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver To: Viresh Kumar References: <20210705024056.ndth2bwn2itii5g3@vireshk-i7> <332af2be-0fb0-a846-8092-49d496fe8b6b@intel.com> <20210705043841.zujwo672nfdndpg2@vireshk-i7> From: Jie Deng Message-ID: <6aabc877-673a-e2bc-da2d-ec6741b4159b@intel.com> Date: Mon, 5 Jul 2021 14:22:15 +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: <20210705043841.zujwo672nfdndpg2@vireshk-i7> Content-Language: en-US Cc: yu1.wang@intel.com, arnd@arndb.de, mst@redhat.com, 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, andriy.shevchenko@linux.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-Transfer-Encoding: base64 Content-Type: text/plain; charset="utf-8"; Format="flowed" Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" Ck9uIDIwMjEvNy81IDEyOjM4LCBWaXJlc2ggS3VtYXIgd3JvdGU6Cj4gT24gMDUtMDctMjEsIDEx OjQ1LC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