linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-mips@vger.kernel.org>
Cc: <tsbogend@alpha.franken.de>, <dengcheng.zhu@imgtec.com>,
	<Steven.Hill@imgtec.com>, <Qais.Yousef@imgtec.com>,
	<blogic@openwrt.org>, <yangyingliang@huawei.com>
Subject: [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
Date: Fri, 4 Nov 2022 11:39:44 +0800	[thread overview]
Message-ID: <20221104033945.1120044-2-yangyingliang@huawei.com> (raw)
In-Reply-To: <20221104033945.1120044-1-yangyingliang@huawei.com>

Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically,
it need be freed when module exiting, call put_device() to give up
reference, so that it can be freed in kobject_cleanup() when the
refcount hit to 0. The vpe_device is static, so remove kfree() from
vpe_device_release().

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 arch/mips/kernel/vpe-mt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/vpe-mt.c b/arch/mips/kernel/vpe-mt.c
index bad6b0891b2b..84a82b551ec3 100644
--- a/arch/mips/kernel/vpe-mt.c
+++ b/arch/mips/kernel/vpe-mt.c
@@ -313,7 +313,6 @@ ATTRIBUTE_GROUPS(vpe);
 
 static void vpe_device_release(struct device *cd)
 {
-	kfree(cd);
 }
 
 static struct class vpe_class = {
@@ -497,6 +496,7 @@ int __init vpe_module_init(void)
 	device_del(&vpe_device);
 
 out_class:
+	put_device(&vpe_device);
 	class_unregister(&vpe_class);
 
 out_chrdev:
@@ -509,7 +509,7 @@ void __exit vpe_module_exit(void)
 {
 	struct vpe *v, *n;
 
-	device_del(&vpe_device);
+	device_unregister(&vpe_device);
 	class_unregister(&vpe_class);
 	unregister_chrdev(major, VPE_MODULE_NAME);
 
-- 
2.25.1


  reply	other threads:[~2022-11-04  3:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04  3:39 [PATCH v2 0/2] MIPS: fix possible memory leak while module exiting Yang Yingliang
2022-11-04  3:39 ` Yang Yingliang [this message]
2022-11-22 11:21   ` [PATCH v2 1/2] MIPS: vpe-mt: " Thomas Bogendoerfer
2022-11-22 11:41     ` Yang Yingliang
2022-11-22 12:07       ` Thomas Bogendoerfer
2022-11-04  3:39 ` [PATCH v2 2/2] MIPS: vpe-cmp: " Yang Yingliang
2022-11-22 12:29 ` [PATCH v2 0/2] MIPS: " Thomas Bogendoerfer

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=20221104033945.1120044-2-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=Qais.Yousef@imgtec.com \
    --cc=Steven.Hill@imgtec.com \
    --cc=blogic@openwrt.org \
    --cc=dengcheng.zhu@imgtec.com \
    --cc=linux-mips@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /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).