From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <mdf@kernel.org>, <hao.wu@intel.com>, <yilun.xu@intel.com>,
<trix@redhat.com>, <russell.h.weight@intel.com>,
<linux-fpga@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH RESEND] fpga: region: Fix possible memory leak in fpga_region_register_full()
Date: Thu, 28 Sep 2023 17:16:36 +0800 [thread overview]
Message-ID: <20230928091636.1209914-1-ruanjinjie@huawei.com> (raw)
If device_register() fails in fpga_region_register_full(), the region
allocated by kzalloc() and the id allocated by ida_alloc() also need be
freed otherwise will cause memory leak.
Fixes: 8886a579744f ("fpga: region: Use standard dev_release for class driver")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/fpga/fpga-region.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
index b364a929425c..9dc6314976ef 100644
--- a/drivers/fpga/fpga-region.c
+++ b/drivers/fpga/fpga-region.c
@@ -228,12 +228,13 @@ fpga_region_register_full(struct device *parent, const struct fpga_region_info *
ret = device_register(®ion->dev);
if (ret) {
- put_device(®ion->dev);
- return ERR_PTR(ret);
+ goto err_put_device;
}
return region;
+err_put_device:
+ put_device(®ion->dev);
err_remove:
ida_free(&fpga_region_ida, id);
err_free:
--
2.34.1
next reply other threads:[~2023-09-28 9:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 9:16 Jinjie Ruan [this message]
2023-09-28 14:02 ` [PATCH RESEND] fpga: region: Fix possible memory leak in fpga_region_register_full() Xu Yilun
2023-09-28 15:45 ` Russ Weight
2023-10-07 9:15 ` Ruan Jinjie
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=20230928091636.1209914-1-ruanjinjie@huawei.com \
--to=ruanjinjie@huawei.com \
--cc=hao.wu@intel.com \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdf@kernel.org \
--cc=russell.h.weight@intel.com \
--cc=trix@redhat.com \
--cc=yilun.xu@intel.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).