Received: by 2002:a9a:45c2:0:b029:115:3f2f:b9e1 with SMTP id r2csp820881lko; Sun, 4 Jul 2021 23:31:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZDAbxOaX17hsg8J8SElLifPREsTS5ObjFNUYXMVeZy23Maw98pQP6JHoQxWg5yTL5P5r3 X-Received: by 2002:a6b:b882:: with SMTP id i124mr10789348iof.80.1625466663670; Sun, 04 Jul 2021 23:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625466663; cv=none; d=google.com; s=arc-20160816; b=NXbD8PWHTWA/yeKhcMZKDEdDTkkn3H/i8lIKgxAEz2SzsZ3CzrB7vxyaepQX7S49MX /Rbm64pfAXDxN87G80OCgwOn9nxOnw9SRmn3VqgjWhBOfFMQ5/RGdQtUacw/PMvEz1Ju xynd8dcrdO0xojkrI4FlasnMzxpq8bVXtZUmA4iNf0KJH6ovS1PkirmeTFjkVbz3PZeQ qownO8my9zwrpC+yqOIXaYyLZhIOqrycmmKMVRQ5xmlOpoq1lwst50QdNOn05l62Zffn Ph7MU7vKgqvC4rLqxQCmxyESDq3THc1BpdqL+vymNJrmepz9WKwKwbxDF6DlgMuL4J9g gz3g== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=kCy8PdVHeBTIQi07/Sw1LRfb7Q/EXacATKTbYu+2Fck=; b=q8pkth2r7DeZuMptIoVpYlvRp4nUWnpa/eZG2TQnqFd/wv+LusTOJM27iT4f0RCYXo 4zj+hCD+hYRGibkktwRXtqwiQDAQbuvZ3Tt/ssQIgKzn3jKfzsJzM3aGDfs2TARDhyIL 3/fozUNPzpLzCm1b0LZfeBJCqT7aO82UQGgAQysMCYUTRgFnVmmSqFaWDQrIRgorLCkx L0Vn7GKWglsXGTp5iAWrSS8Z520hVPzonCjfcMxUDbEZsquvZR2CCLzHsVEsrJwGLUaL AzcexH0xTi1cKxqVxSSXdkUIsZ5iO2wfey7KkChSdmPZD7uUA0ZJDN6im6nzTiZum1wt 8/Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QVj/ekGN"; 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 z12si14111314iow.31.2021.07.04.23.30.49; Sun, 04 Jul 2021 23:31:03 -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="QVj/ekGN"; 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 S229817AbhGEGcr (ORCPT + 99 others); Mon, 5 Jul 2021 02:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbhGEGcp (ORCPT ); Mon, 5 Jul 2021 02:32:45 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FF68C061760 for ; Sun, 4 Jul 2021 23:30:09 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id cx9-20020a17090afd89b0290170a3e085edso11185630pjb.0 for ; Sun, 04 Jul 2021 23:30:09 -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:content-transfer-encoding:in-reply-to :user-agent; bh=kCy8PdVHeBTIQi07/Sw1LRfb7Q/EXacATKTbYu+2Fck=; b=QVj/ekGNd3LBhRATDInKpV5990ELYYESSnDGSuO7s+S/DGN6i/2CHSGVagsK/5dtEB OnUSmlD8FN9S25MJ3QAtWFtjXNCNA105DEEPRQYLlOj96d1x7IIV7eJ2zHttF0nDN+7+ pspEb/iyZSFI+0Z/hM6lSrMpxYx1wm+730lobEUZHlNvd2ZVg+61Ybr0LgSiSyk95mtM hroAfuUkvIXQnI73a62/3/wSCn71CKnpD9qzbE29qEAA/4YvVla7c+/hXxk1lTOnkDgp 3+C9JXZhJGH5MGkoEAN3uJ8Ui0GAGJ272cr80ZlHuQ9wdeM3KAExsYCl6NZg05cpY1vG 0oCQ== 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:content-transfer-encoding :in-reply-to:user-agent; bh=kCy8PdVHeBTIQi07/Sw1LRfb7Q/EXacATKTbYu+2Fck=; b=bw4RS2jjnbS9RxP9fnFBkWVA4ZrGxATQjQJ22OAe3Zu25e/S3UAa4NyeerRvWPmR7G FBOmSeen3adWH1NYY15+Lp5cjRaDP2YLBCxxgQ6bzVBgF0N5Apwz4LMtZ/JIizmDWoK2 5UiwZQlOLhVHVM9/piT/zD8nOfLP7FvIelTWXhjrsAcqfxlBjWsWce92oXkXR+G//oFZ qA1mBaTUBJIQsFPU6t4S8BQWh3C2cPDkJm4QJmhJTOOmb8zIip1EkM1Aqw6uPIjWQxZu DwtaKgA/SCvnLeC9hpctjoavmGDnb9avOOEMdnaBvR8exQeqNLHraZP2DSmP0s4+A9/M /2Kg== X-Gm-Message-State: AOAM531CWu0PB3eo/iNgtt6qdu7p7pe53CRanKAt7x3af5f1Aj4gEs6v oxDbBotRobX0rbhtIgM3DDPO9g== X-Received: by 2002:a17:90b:4b87:: with SMTP id lr7mr13983622pjb.214.1625466606283; Sun, 04 Jul 2021 23:30:06 -0700 (PDT) Received: from localhost ([106.201.108.2]) by smtp.gmail.com with ESMTPSA id v21sm19445795pju.47.2021.07.04.23.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 23:30:05 -0700 (PDT) Date: Mon, 5 Jul 2021 12:00:03 +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 Subject: Re: [PATCH v12] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20210705063003.a45ic3wn74nre6xe@vireshk-i7> References: <20210705024056.ndth2bwn2itii5g3@vireshk-i7> <332af2be-0fb0-a846-8092-49d496fe8b6b@intel.com> <20210705043841.zujwo672nfdndpg2@vireshk-i7> <6aabc877-673a-e2bc-da2d-ec6741b4159b@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6aabc877-673a-e2bc-da2d-ec6741b4159b@intel.com> User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05-07-21, 14:22, Jie Deng wrote: > 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. Do you see reqs[i] to ever be NULL here ? If not, then if (req) is like if (true). Why would you want to have something like that ? -- viresh