From: Navid Emamdoost <navid.emamdoost@gmail.com>
To: Ian Abbott <abbotti@mev.co.uk>,
H Hartley Sweeten <hsweeten@visionengravers.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Navid Emamdoost <navid.emamdoost@gmail.com>,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Cc: emamd001@umn.edu
Subject: [PATCH] staging: comedi: drivers: Fix memory leak in gsc_hpdi_auto_attach
Date: Sat, 14 Dec 2019 19:33:03 -0600 [thread overview]
Message-ID: <20191215013306.18880-1-navid.emamdoost@gmail.com> (raw)
In the implementation of gsc_hpdi_auto_attach(), the allocated dma
description is leaks in case of alignment error, or failure of
gsc_hpdi_setup_dma_descriptors() or comedi_alloc_subdevices(). Release
devpriv->dma_desc via dma_free_coherent().
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
drivers/staging/comedi/drivers/gsc_hpdi.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c
index 4bdf44d82879..c0c7047a6d1b 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -633,16 +633,17 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev,
if (devpriv->dma_desc_phys_addr & 0xf) {
dev_warn(dev->class_dev,
" dma descriptors not quad-word aligned (bug)\n");
- return -EIO;
+ retval = -EIO;
+ goto release_dma_desc;
}
retval = gsc_hpdi_setup_dma_descriptors(dev, 0x1000);
if (retval < 0)
- return retval;
+ goto release_dma_desc;
retval = comedi_alloc_subdevices(dev, 1);
if (retval)
- return retval;
+ goto release_dma_desc;
/* Digital I/O subdevice */
s = &dev->subdevices[0];
@@ -660,6 +661,15 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev,
s->cancel = gsc_hpdi_cancel;
return gsc_hpdi_init(dev);
+
+release_dma_desc:
+ if (devpriv->dma_desc)
+ dma_free_coherent(&pcidev->dev,
+ sizeof(struct plx_dma_desc) *
+ NUM_DMA_DESCRIPTORS,
+ devpriv->dma_desc,
+ devpriv->dma_desc_phys_addr);
+ return retval;
}
static void gsc_hpdi_detach(struct comedi_device *dev)
--
2.17.1
next reply other threads:[~2019-12-15 1:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-15 1:33 Navid Emamdoost [this message]
2019-12-15 15:07 ` [PATCH] staging: comedi: drivers: Fix memory leak in gsc_hpdi_auto_attach Markus Elfring
2019-12-16 10:36 ` Ian Abbott
2019-12-16 20:18 ` Navid Emamdoost
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=20191215013306.18880-1-navid.emamdoost@gmail.com \
--to=navid.emamdoost@gmail.com \
--cc=abbotti@mev.co.uk \
--cc=devel@driverdev.osuosl.org \
--cc=emamd001@umn.edu \
--cc=gregkh@linuxfoundation.org \
--cc=hsweeten@visionengravers.com \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).