MIPS: fix possible memory leak while module exiting
v2 cover MIPS: fix possible memory leak while module exiting
This patchset fixes two device name leaks while module exiting in normal or error path.
v1 -> v2:
Add fix tag in patch #1.
Yang Yingliang (2):
MIPS: vpe-mt: fix possible memory leak while module exiting
MIPS: vpe-cmp: fix possible memory leak while module exiting
arch/mips/kernel/vpe-cmp.c | 4 ++-- arch/mips/kernel/vpe-mt.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 MIPS: vpe-mt: fix possible memory leak while module exiting
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().
--- arch/mips/kernel/vpe-mt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/kernel/vpe-mt.c +2 -2
@@ -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 );
Signature · 1 line
2.25.1
Thomas Bogendoerfer
maintainerRe: [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
Quoted 18 lines · Yang Yingliang
Afer commit
1fa5ae857bb1("driver core: get rid of struct device'sbus_idstring array"), the name of device is allocated dynamically, it need be freed when module exiting, callput_device()to give up reference, so that it can be freed inkobject_cleanup()when the refcount hit to 0. Thevpe_deviceis static, so removekfree()fromvpe_device_release().Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")Signed-off-by Yang Yingliang <[email protected]>--- arch/mips/kernel/vpe-mt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/mips/kernel/vpe-mt.c +0
-0
arch/mips/kernel/vpe-mt.c ATTRIBUTE_GROUPS(vpe); · line 316
Quoted 5 lines
arch/mips/kernel/vpe-mt.c +0
-1@@ -313,7 +313,6 @@ ATTRIBUTE_GROUPS(vpe);static void vpe_device_release (struct device *cd) { -kfree (cd); }
as this is empty now, we can IMHO remove the function completly. Same for the other patch in this series.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]
Re: [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
Hi,
Quoted 20 lines · Thomas Bogendoerfer
Quoted 19 lines · Yang Yingliang
Afer commit
1fa5ae857bb1("driver core: get rid of struct device'sbus_idstring array"), the name of device is allocated dynamically, it need be freed when module exiting, callput_device()to give up reference, so that it can be freed inkobject_cleanup()when the refcount hit to 0. Thevpe_deviceis static, so removekfree()fromvpe_device_release().Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")Signed-off-by Yang Yingliang <[email protected]>--- arch/mips/kernel/vpe-mt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/mips/kernel/vpe-mt.c +0
-0@@ -313,7 +313,6 @@ ATTRIBUTE_GROUPS(vpe);
Quoted 6 lines
arch/mips/kernel/vpe-mt.c ATTRIBUTE_GROUPS(vpe); · line 316
Quoted 4 lines
arch/mips/kernel/vpe-mt.c +0
-1static void vpe_device_release (struct device *cd) { -kfree (cd); }as this is empty now, we can IMHO remove the function completly. Same for the other patch in this series.
It can not be removed, or it will cause WARNING in device_release() when calling put_device()/device_unregister().
static void device_release(struct kobject *kobj)
{
...
if (dev->release)
dev->release(dev);
else if (dev->type && dev->type->release)
dev->type->release(dev);
else if (dev->class && dev->class->dev_release)
dev->class->dev_release(dev);
else
WARN(1, KERN_ERR "Device '%s' does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.\n", dev_name(dev)); // WANING here
...
}
Thanks,
Yang
Quoted 3 lines
Thomas.
Thomas Bogendoerfer
maintainerRe: [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
Quoted 36 lines · Yang Yingliang
Hi,
Quoted 14 lines · Thomas Bogendoerfer
Quoted 13 lines · Yang Yingliang
Afer commit
1fa5ae857bb1("driver core: get rid of struct device'sbus_idstring array"), the name of device is allocated dynamically, it need be freed when module exiting, callput_device()to give up reference, so that it can be freed inkobject_cleanup()when the refcount hit to 0. Thevpe_deviceis static, so removekfree()fromvpe_device_release().Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")Signed-off-by Yang Yingliang <[email protected]>--- arch/mips/kernel/vpe-mt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Quoted 11 lines
arch/mips/kernel/vpe-mt.c ATTRIBUTE_GROUPS(vpe); · line 315
Quoted 9 lines
arch/mips/kernel/vpe-mt.c +0
-1@@ -313,7 +313,6 @@ ATTRIBUTE_GROUPS(vpe);static void vpe_device_release (struct device *cd) { -kfree (cd); }as this is empty now, we can IMHO remove the function completly. Same for the other patch in this series.
It can not be removed, or it will cause WARNING in
device_release()when calling
put_device()/device_unregister().static void
device_release(struct kobject *kobj)
{
...
Quoted 11 lines
if (
dev->release)
dev->release(dev);
else if (dev->type&&dev->type->release)dev->type->release(dev);
else if (dev->class&&dev->class->dev_release)dev->class->dev_release(dev);
else
WARN(1,KERN_ERR"Device '%s' does not have arelease()function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.\n",
dev_name(dev)); // WANING here
you are right, thank you for looking into that,
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]
PATCH v2 2/2 MIPS: vpe-cmp: fix possible memory leak while module exiting
In reply to Yang Yingliangdev_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().
--- arch/mips/kernel/vpe-cmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/kernel/vpe-cmp.c +2 -2
@@ -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 @@ int __init vpe_module_init(void)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 );
Signature · 1 line
2.25.1
Thomas Bogendoerfer
maintainerQuoted 6 lines · Yang Yingliang
This patchset fixes two device name leaks while module exiting in normal or error path.
v1 -> v2:
Add fix tag in patch #1.
Quoted 10 lines
Yang Yingliang (2):
MIPS: vpe-mt: fix possible memory leak while module exiting
MIPS: vpe-cmp: fix possible memory leak while module exitingarch/mips/kernel/vpe-cmp.c | 4 ++-- arch/mips/kernel/vpe-mt.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)Signature · 1 line
2.25.1
series applied to mips-next.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]