From: Baolu Lu <baolu.lu@linux.intel.com>
To: Miaoqian Lin <linmq006@gmail.com>, Joerg Roedel <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Kevin Tian <kevin.tian@intel.com>,
Eric Auger <eric.auger@redhat.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: baolu.lu@linux.intel.com
Subject: Re: [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner
Date: Tue, 3 Jan 2023 09:26:19 +0800 [thread overview]
Message-ID: <ffe919f3-f4f2-b378-947f-4cf704ad8950@linux.intel.com> (raw)
In-Reply-To: <20221230083100.1489569-1-linmq006@gmail.com>
On 12/30/22 4:31 PM, Miaoqian Lin wrote:
> iommu_group_get() returns the group with the reference incremented.
> Move iommu_group_get() after owner check to fix the refcount leak.
An empty @owner is a more serious problem than refcount leak. It should
not happen, so a WARN_ON() was added there.
Anyway, your change makes the code better.
>
> Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> drivers/iommu/iommu.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index de91dd88705b..3a7dd8b61fab 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3185,14 +3185,16 @@ EXPORT_SYMBOL_GPL(iommu_group_claim_dma_owner);
> */
> int iommu_device_claim_dma_owner(struct device *dev, void *owner)
> {
> - struct iommu_group *group = iommu_group_get(dev);
> + struct iommu_group *group = NULL;
No need to set NULL to group.
> int ret = 0;
>
> - if (!group)
> - return -ENODEV;
> if (WARN_ON(!owner))
> return -EINVAL;
>
> + group = iommu_group_get(dev);
> + if (!group)
> + return -ENODEV;
> +
> mutex_lock(&group->mutex);
> if (group->owner_cnt) {
> if (group->owner != owner) {
Others look good to me.
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
--
Best regards,
baolu
next prev parent reply other threads:[~2023-01-03 1:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-30 8:31 Miaoqian Lin
2023-01-03 1:26 ` Baolu Lu [this message]
2023-01-13 12:39 ` Joerg Roedel
2023-01-03 6:30 Miaoqian Lin
2023-01-03 23:12 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ffe919f3-f4f2-b378-947f-4cf704ad8950@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linmq006@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®