]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
MIPS: vpe-cmp: fix possible memory leak while module exiting
authorYang Yingliang <yangyingliang@huawei.com>
Fri, 4 Nov 2022 03:39:45 +0000 (11:39 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jan 2023 11:07:14 +0000 (12:07 +0100)
[ Upstream commit c5ed1fe0801f0c66b0fbce2785239a5664629057 ]

dev_set_name() allocates memory for name, 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: 17a1d523aa58 ("MIPS: APRP: Add VPE loader support for CMP platforms.")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/mips/kernel/vpe-cmp.c

index 9268ebc0f61e6e3edbd95c814a71a712f599d72f..903c07bdc92d90e32f139f82e43155b2e4ac78ae 100644 (file)
@@ -75,7 +75,6 @@ ATTRIBUTE_GROUPS(vpe);
 
 static void vpe_device_release(struct device *cd)
 {
-       kfree(cd);
 }
 
 static struct class vpe_class = {
@@ -157,6 +156,7 @@ out_dev:
        device_del(&vpe_device);
 
 out_class:
+       put_device(&vpe_device);
        class_unregister(&vpe_class);
 
 out_chrdev:
@@ -169,7 +169,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);