mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shang XiaoJing <shangxiaojing@huawei.com>
To: <abbotti@mev.co.uk>, <hsweeten@visionengravers.com>,
	<gregkh@linuxfoundation.org>, <linux-kernel@vger.kernel.org>
Cc: <shangxiaojing@huawei.com>
Subject: [PATCH] comedi: drivers: pcl730: Fix potential memory leak in pcl730_attach()
Date: Tue, 22 Nov 2022 20:04:28 +0800	[thread overview]
Message-ID: <20221122120428.25069-1-shangxiaojing@huawei.com> (raw)

pcl730_attach() calls comedi_request_region() and won't release the
resource allocated by alloc_resource() when pcl730_attach() failed latter.
Add release_region() to prevent memory leak.

Fixes: 6f9aa29b47f6 ("staging: comedi: pcl730: use comedi_request_region()")
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
 drivers/comedi/drivers/pcl730.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/comedi/drivers/pcl730.c b/drivers/comedi/drivers/pcl730.c
index d2733cd5383d..c463de8a14e1 100644
--- a/drivers/comedi/drivers/pcl730.c
+++ b/drivers/comedi/drivers/pcl730.c
@@ -274,8 +274,14 @@ static int pcl730_attach(struct comedi_device *dev,
 		return ret;
 
 	ret = comedi_alloc_subdevices(dev, board->n_subdevs);
-	if (ret)
+	if (ret) {
+		if (dev->iobase && dev->iolen) {
+			release_region(dev->iobase, dev->iolen);
+			dev->iobase = 0;
+			dev->iolen = 0;
+		}
 		return ret;
+	}
 
 	subdev = 0;
 
-- 
2.17.1


             reply	other threads:[~2022-11-22 12:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 12:04 Shang XiaoJing [this message]
2022-11-22 12:18 ` Ian Abbott
2022-11-22 12:24   ` shangxiaojing

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=20221122120428.25069-1-shangxiaojing@huawei.com \
    --to=shangxiaojing@huawei.com \
    --cc=abbotti@mev.co.uk \
    --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

all inboxes | Powered by JetHome®