From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <linux-fpga@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Moritz Fischer <mdf@kernel.org>, Wu Hao <hao.wu@intel.com>,
Xu Yilun <yilun.xu@intel.com>, Tom Rix <trix@redhat.com>,
Russ Weight <russell.h.weight@intel.com>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH] fpga: fpga-mgr: Fix possible memory leak in fpga_mgr_register_full()
Date: Thu, 28 Sep 2023 17:59:08 +0800 [thread overview]
Message-ID: <20230928095909.1298103-1-ruanjinjie@huawei.com> (raw)
If device_register() fails in fpga_mgr_register_full(), the mgr
allocated by kzalloc() and the id allocated by ida_alloc() also need be
freed otherwise will cause memory leak.
Fixes: 4ba0b2c294fe ("fpga: mgr: Use standard dev_release for class driver")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/fpga/fpga-mgr.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index 06651389c592..9724f192ba16 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -827,13 +827,13 @@ fpga_mgr_register_full(struct device *parent, const struct fpga_manager_info *in
mgr->state = fpga_mgr_state(mgr);
ret = device_register(&mgr->dev);
- if (ret) {
- put_device(&mgr->dev);
- return ERR_PTR(ret);
- }
+ if (ret)
+ goto error_put_device;
return mgr;
+error_put_device:
+ put_device(&mgr->dev);
error_device:
ida_free(&fpga_mgr_ida, id);
error_kfree:
--
2.34.1
reply other threads:[~2023-09-28 10:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230928095909.1298103-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).