Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2820196pxk; Mon, 28 Sep 2020 00:15:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM21wVqQRJrnN7Bpn3Rr8nmX8m1hd3SvdYyf4RW5wcCT6BN4mOyenrHcxsEiETGFu45ZoR X-Received: by 2002:a50:fc08:: with SMTP id i8mr229905edr.257.1601277328453; Mon, 28 Sep 2020 00:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601277328; cv=none; d=google.com; s=arc-20160816; b=hCpZdMfnNKy6L8gxqvSVk9a0KcaEIpDa4dlPLcaFxq1NqDZEX3EMLoiRxukHJoKUXM d6Oey1D6xdS7//JR2tbWoLwkEWsDmddT2kzbtFfq5kRvexH3gppQkm1qUtfBkAA6nBFO SnajvBeE3f82ZDHx0srPls2C/Ew+9+wSgzn41jbqTDUzy+amTu6pl8BborzAiHRnPrGZ fOXztyIWRseFwvejdEdRkuVApVhJT8zmaxX+ueuA6n6yTo5X3/QRuek8ZgfjU2v8Ici4 yotv7ezmjqU/zKwM06JRpPPdnBiJbVSQ4c4EapCveZ9oQWYOCceWD+EwwV+/iCDBq9IN auCA== 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=dKVXsIoVUAuhSPTXKz6orVntDM81DbNac5gyHMzAPn0=; b=WUKUehBQCPIv+Z9F8hBl/6hq/CRyY1Q0b+uDyTXR5+dAaiazRo4yvqm1ZaweCGGtS4 X1CNiT/9dHkvBygNfdWjD/0Jm/d6gZOdGaHUXcfdbGsnhavoip1FXp3n7V04p8ZEIDKW vx+vSXZRGC7wOTZxELzlaB21gjswNF+YaThkMU+F6Nk+rJ3JlbnbRlu4BH/jB7l1jSCN R2YkVMspgKfcuURbwaFLZT33MvBSewHGn3E8Pgkf/gB8ICgBi7TbBwYOkkv88rHD9vQx YkaZvYP3ZBa5HApTPDufp9xaviuJzGyq5AZG5yWqkL7kt0NZNMV+MjoTh9Z4zkF2LP/U G9wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QVueCi8X; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch14si69801ejb.360.2020.09.28.00.15.04; Mon, 28 Sep 2020 00:15:28 -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=@gmail.com header.s=20161025 header.b=QVueCi8X; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726442AbgI1HOB (ORCPT + 99 others); Mon, 28 Sep 2020 03:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbgI1HOB (ORCPT ); Mon, 28 Sep 2020 03:14:01 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02293C0613CE; Mon, 28 Sep 2020 00:14:00 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id o5so10946447wrn.13; Mon, 28 Sep 2020 00:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dKVXsIoVUAuhSPTXKz6orVntDM81DbNac5gyHMzAPn0=; b=QVueCi8XQiMhkjOzIKmaTIysaN6WlOZE2WfLd9SNZ5wlmdtIVcuNGiYUTgd5NPAOo9 hi0/5KDd4YUjJbJT8RWlpYw//5248xsoPdhCkIxJ/yCMVJnV4EZpXw045OWTrPehnP7D WYgFexBGVJN5OKD/8rFXsmQYtJIpanOjg0myKVLKFLmGWxe/L9Aa9pEE6C+ocaeut3sh V4+qB1XJuh/JcJy49H9yyECjtXLR+Ik0M6DGifAVousD2WiH7oQNK84LM8DYvwZMI9vG pfvYmgeCxdkt3UV6URosdCh3QNZ8m9hiwSIWfiGZ+7fTX4hD1q7mSZQdN+HcRD4b58Qi isyA== 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=dKVXsIoVUAuhSPTXKz6orVntDM81DbNac5gyHMzAPn0=; b=TMBK4Zf3wP0omxvDLu8rQkBGju7+JwoUEzN2vB2FKtaw0Jr9EW1onh/vZc1OGi3yLc gXNf6dVYlQmBTsUTESKP5gFr9vb6tX1F6sLn+6YQ02nPIcB2FjeBwezmdoM1a6lpFSci xDnnYlKsq/Lposvmlklnf0hyzE5YKM7IjET8oUugOr/DIv3SGBFS2cMYUCZjmOPMQAJQ 9qCYldnzbkAXoXEt3Tn8v0j6/eAahEGL2J6YR/E3eLQ4AZR72qdImM9PuQ/RKIH7Tr1D hGGpt7yXGH+zrhO/KiCzwOxxP/Z64Ow3AkG/KGAyvhLN80VGEMiSA6XJxqDg0FewDSrS e99A== X-Gm-Message-State: AOAM530osRDUvx5mGnIMiSBJE8+q3BpMJXliTCiKiqsPltJ3pLLj49rS i5c1cjSXQKKtLwuJol6JzVnD2D5fzWA= X-Received: by 2002:adf:d0cb:: with SMTP id z11mr31038wrh.192.1601277239454; Mon, 28 Sep 2020 00:13:59 -0700 (PDT) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id n10sm27928wmk.7.2020.09.28.00.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 00:13:57 -0700 (PDT) Date: Mon, 28 Sep 2020 09:13:56 +0200 From: Thierry Reding To: Nicolin Chen Cc: joro@8bytes.org, krzk@kernel.org, vdumpa@nvidia.com, jonathanh@nvidia.com, linux-tegra@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] iommu/tegra-smmu: Unwrap tegra_smmu_group_get Message-ID: <20200928071356.GD2837573@ulmo> References: <20200926080719.6822-1-nicoleotsuka@gmail.com> <20200926080719.6822-2-nicoleotsuka@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eqp4TxRxnD4KrmFZ" Content-Disposition: inline In-Reply-To: <20200926080719.6822-2-nicoleotsuka@gmail.com> User-Agent: Mutt/1.14.7 (2020-08-29) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --eqp4TxRxnD4KrmFZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 26, 2020 at 01:07:15AM -0700, Nicolin Chen wrote: > The tegra_smmu_group_get was added to group devices in different > SWGROUPs and it'd return a NULL group pointer upon a mismatch at > tegra_smmu_find_group(), so for most of clients/devices, it very > likely would mismatch and need a fallback generic_device_group(). >=20 > But now tegra_smmu_group_get handles devices in same SWGROUP too, > which means that it would allocate a group for every new SWGROUP > or would directly return an existing one upon matching a SWGROUP, > i.e. any device will go through this function. >=20 > So possibility of having a NULL group pointer in device_group() > is upon failure of either devm_kzalloc() or iommu_group_alloc(). > In either case, calling generic_device_group() no longer makes a > sense. Especially for devm_kzalloc() failing case, it'd cause a > problem if it fails at devm_kzalloc() yet succeeds at a fallback > generic_device_group(), because it does not create a group->list > for other devices to match. >=20 > This patch simply unwraps the function to clean it up. >=20 > Signed-off-by: Nicolin Chen > --- > drivers/iommu/tegra-smmu.c | 19 ++++--------------- > 1 file changed, 4 insertions(+), 15 deletions(-) >=20 > diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c > index 0becdbfea306..6335285dc373 100644 > --- a/drivers/iommu/tegra-smmu.c > +++ b/drivers/iommu/tegra-smmu.c > @@ -903,11 +903,13 @@ static void tegra_smmu_group_release(void *iommu_da= ta) > mutex_unlock(&smmu->lock); > } > =20 > -static struct iommu_group *tegra_smmu_group_get(struct tegra_smmu *smmu, > - unsigned int swgroup) > +static struct iommu_group *tegra_smmu_device_group(struct device *dev) > { > + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); > + struct tegra_smmu *smmu =3D dev_iommu_priv_get(dev); > const struct tegra_smmu_group_soc *soc; > struct tegra_smmu_group *group; > + int swgroup =3D fwspec->ids[0]; This should be unsigned int to match the type of swgroup elsewhere. Also, it might not be worth having an extra local variable for this since it's only used once. Thierry --eqp4TxRxnD4KrmFZ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAl9xjTEACgkQ3SOs138+ s6Hb3BAAmlSBf17eRIqR2c2OKS3u6J4Gm8+F2mKHd+5sC0MgnQVSzME9EJCuuiMb oPvGwcxTnuabt/CvTD+s7O9dRsDP9vfmYADkWhpvfF5fY+QEbaRdmy7H8dECi7Wp 0UqfdEY99sE5Tj2z+mtywlTFrcHPzHuKPrOEYyjorIY2Fi569yRERhB8Bbs9Rkgc QRrB2R3rel+1aL7gYauQvkEJOoBFAT2i6Ebg6qaVFl4yPtHmRwALHgyEmV6SRT7D 3CUIaW8g8pEulOoM1YzKyAThO1NKH2GTp/+3/+cjFl7qK654a0J5inAQrYp0fF7+ L/GcJbflazVj766H4nQYdE6PbwEBfNt8BDUDDeIAAasBgiJ+I9/97DnJodt0Q5Kq Jkdg0OO+q050bjutL5+QYLpHQPaykZzIIGQhIqXw/VKum26Zj4ETzT6u4sqO0PVG gHPiUmN3ioC3UEfvzHd/xJz1a+nBN6LgHXH4rQEsuu7ZfbWmVIiWY/aEB13jUj3l i4IrXLTt05GnspNSeoVkeXpMaJfovn/ocESIXmxL3Yz4yf09rNzBxZlypFhCbq7q GUk7WKpXG2i0gtvCMXIzPTGcC0ewhAfI/bzz2FsfYX20e7a2ao7Qg9DqvO4QmXR1 loq35HGpMRSodtzvSeuEQJMV1uwebJgHq1EnitQvP3X9JVKwLJs= =UiGV -----END PGP SIGNATURE----- --eqp4TxRxnD4KrmFZ--