Skip to content

Commit

Permalink
MIPS: vpe-cmp: fix possible memory leak while module exiting
Browse files Browse the repository at this point in the history
[ Upstream commit c5ed1fe ]

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: 17a1d52 ("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>
  • Loading branch information
Yang Yingliang authored and gregkh committed Dec 31, 2022
1 parent e820a81 commit 46be3ee
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arch/mips/kernel/vpe-cmp.c
Expand Up @@ -75,7 +75,6 @@ ATTRIBUTE_GROUPS(vpe);

static void vpe_device_release(struct device *cd)
{
kfree(cd);
}

static struct class vpe_class = {
Expand Down Expand Up @@ -157,6 +156,7 @@ int __init vpe_module_init(void)
device_del(&vpe_device);

out_class:
put_device(&vpe_device);
class_unregister(&vpe_class);

out_chrdev:
Expand All @@ -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);

Expand Down

0 comments on commit 46be3ee

Please sign in to comment.