From: dinghao.liu@zju.edu.cn
To: "Lu Baolu" <baolu.lu@linux.intel.com>
Cc: kjlu@umn.edu, "David Woodhouse" <dwmw2@infradead.org>,
"Joerg Roedel" <joro@8bytes.org>, "Will Deacon" <will@kernel.org>,
"Jiang Liu" <jiang.liu@linux.intel.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: Re: [PATCH] iommu/intel: Fix memleak in intel_irq_remapping_alloc
Date: Sun, 3 Jan 2021 12:08:31 +0800 (GMT+08:00) [thread overview]
Message-ID: <50870a42.15f1a.176c66eaf92.Coremail.dinghao.liu@zju.edu.cn> (raw)
In-Reply-To: <18add30d-a830-c531-6fd2-58a1898b157f@linux.intel.com>
> Hi,
>
> On 2021/1/2 17:50, Dinghao Liu wrote:
> > When irq_domain_get_irq_data() or irqd_cfg() fails
> > meanwhile i == 0, data allocated by kzalloc() has not
> > been freed before returning, which leads to memleak.
> >
> > Fixes: b106ee63abccb ("irq_remapping/vt-d: Enhance Intel IR driver to support hierarchical irqdomains")
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> > drivers/iommu/intel/irq_remapping.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_remapping.c
> > index aeffda92b10b..cdaeed36750f 100644
> > --- a/drivers/iommu/intel/irq_remapping.c
> > +++ b/drivers/iommu/intel/irq_remapping.c
> > @@ -1354,6 +1354,8 @@ static int intel_irq_remapping_alloc(struct irq_domain *domain,
> > irq_cfg = irqd_cfg(irq_data);
> > if (!irq_data || !irq_cfg) {
> > ret = -EINVAL;
> > + kfree(data);
> > + data = NULL;
>
> Do you need to check (i == 0) here? @data will not be used anymore as it
> goes to out branch, why setting it to NULL here?
>
data will be passed to ire_data->chip_data when i == 0 and
intel_free_irq_resources() will free it on failure. Thus I
set it to NULL to prevent double-free. However, if we add
a check (i == 0) here, we will not need to set it to NULL.
If this is better, I will resend a new patch soon.
Regards,
Dinghao
next prev parent reply other threads:[~2021-01-03 4:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-02 9:50 Dinghao Liu
2021-01-03 2:40 ` Lu Baolu
2021-01-03 4:08 ` dinghao.liu [this message]
2021-01-03 5:49 ` Lu Baolu
2021-01-03 6:22 ` dinghao.liu
2021-01-05 1:51 ` Lu Baolu
2021-01-05 2:48 ` dinghao.liu
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=50870a42.15f1a.176c66eaf92.Coremail.dinghao.liu@zju.edu.cn \
--to=dinghao.liu@zju.edu.cn \
--cc=baolu.lu@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jiang.liu@linux.intel.com \
--cc=joro@8bytes.org \
--cc=kjlu@umn.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--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®