linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] MIPS: fix possible memory leak while module exiting
@ 2022-11-04  3:39 Yang Yingliang
  2022-11-04  3:39 ` [PATCH v2 1/2] MIPS: vpe-mt: " Yang Yingliang
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Yang Yingliang @ 2022-11-04  3:39 UTC (permalink / raw)
  To: linux-mips
  Cc: tsbogend, dengcheng.zhu, Steven.Hill, Qais.Yousef, blogic, yangyingliang

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
  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
  2022-11-22 11:21   ` 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
  2 siblings, 1 reply; 7+ messages in thread
From: Yang Yingliang @ 2022-11-04  3:39 UTC (permalink / raw)
  To: linux-mips
  Cc: tsbogend, dengcheng.zhu, Steven.Hill, Qais.Yousef, blogic, yangyingliang

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] MIPS: vpe-cmp: fix possible memory leak while module exiting
  2022-11-04  3:39 [PATCH v2 0/2] MIPS: fix possible memory leak while module exiting Yang Yingliang
  2022-11-04  3:39 ` [PATCH v2 1/2] MIPS: vpe-mt: " Yang Yingliang
@ 2022-11-04  3:39 ` Yang Yingliang
  2022-11-22 12:29 ` [PATCH v2 0/2] MIPS: " Thomas Bogendoerfer
  2 siblings, 0 replies; 7+ messages in thread
From: Yang Yingliang @ 2022-11-04  3:39 UTC (permalink / raw)
  To: linux-mips
  Cc: tsbogend, dengcheng.zhu, Steven.Hill, Qais.Yousef, blogic, yangyingliang

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>
---
 arch/mips/kernel/vpe-cmp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/vpe-cmp.c b/arch/mips/kernel/vpe-cmp.c
index e673603e11e5..92140edb3ce3 100644
--- a/arch/mips/kernel/vpe-cmp.c
+++ b/arch/mips/kernel/vpe-cmp.c
@@ -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);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
  2022-11-04  3:39 ` [PATCH v2 1/2] MIPS: vpe-mt: " Yang Yingliang
@ 2022-11-22 11:21   ` Thomas Bogendoerfer
  2022-11-22 11:41     ` Yang Yingliang
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Bogendoerfer @ 2022-11-22 11:21 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: linux-mips, dengcheng.zhu, Steven.Hill, Qais.Yousef, blogic

On Fri, Nov 04, 2022 at 11:39:44AM +0800, Yang Yingliang wrote:
> 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);
>  }

as this is empty now, we can IMHO remove the function completly. Same
for the other patch in this series.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
  2022-11-22 11:21   ` Thomas Bogendoerfer
@ 2022-11-22 11:41     ` Yang Yingliang
  2022-11-22 12:07       ` Thomas Bogendoerfer
  0 siblings, 1 reply; 7+ messages in thread
From: Yang Yingliang @ 2022-11-22 11:41 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: linux-mips, dengcheng.zhu, Steven.Hill, Qais.Yousef, blogic,
	yangyingliang

Hi,

On 2022/11/22 19:21, Thomas Bogendoerfer wrote:
> On Fri, Nov 04, 2022 at 11:39:44AM +0800, Yang Yingliang wrote:
>> 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);
>>   }
> 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
>
> Thomas.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] MIPS: vpe-mt: fix possible memory leak while module exiting
  2022-11-22 11:41     ` Yang Yingliang
@ 2022-11-22 12:07       ` Thomas Bogendoerfer
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Bogendoerfer @ 2022-11-22 12:07 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: linux-mips, dengcheng.zhu, Steven.Hill, Qais.Yousef, blogic

On Tue, Nov 22, 2022 at 07:41:26PM +0800, Yang Yingliang wrote:
> Hi,
> 
> On 2022/11/22 19:21, Thomas Bogendoerfer wrote:
> > On Fri, Nov 04, 2022 at 11:39:44AM +0800, Yang Yingliang wrote:
> > > 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);
> > >   }
> > 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

you are right, thank you for looking into that,

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/2] MIPS: fix possible memory leak while module exiting
  2022-11-04  3:39 [PATCH v2 0/2] MIPS: fix possible memory leak while module exiting Yang Yingliang
  2022-11-04  3:39 ` [PATCH v2 1/2] MIPS: vpe-mt: " Yang Yingliang
  2022-11-04  3:39 ` [PATCH v2 2/2] MIPS: vpe-cmp: " Yang Yingliang
@ 2022-11-22 12:29 ` Thomas Bogendoerfer
  2 siblings, 0 replies; 7+ messages in thread
From: Thomas Bogendoerfer @ 2022-11-22 12:29 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: linux-mips, dengcheng.zhu, Steven.Hill, Qais.Yousef, blogic

On Fri, Nov 04, 2022 at 11:39:43AM +0800, Yang Yingliang wrote:
> 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(-)
> 
> -- 
> 2.25.1

series applied to mips-next.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-22 12:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04  3:39 [PATCH v2 0/2] MIPS: fix possible memory leak while module exiting Yang Yingliang
2022-11-04  3:39 ` [PATCH v2 1/2] MIPS: vpe-mt: " Yang Yingliang
2022-11-22 11:21   ` 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

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).