2010-02-10 11:35:47

by Laurent Pinchart

[permalink] [raw]
Subject: [PATCH] class: Free the class private data in class_unregister

Fix a memory leak by freeing the memory allocated in __class_register
for the class private data.

Signed-off-by: Laurent Pinchart <[email protected]>
---
drivers/base/class.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 161746d..a9449b3 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -200,6 +200,7 @@ void class_unregister(struct class *cls)
pr_debug("device class '%s': unregistering\n", cls->name);
remove_class_attrs(cls);
kset_unregister(&cls->p->class_subsys);
+ kfree(cls->p);
}

static void class_create_release(struct class *cls)
--
1.6.4.4


2010-02-10 12:32:57

by Laurent Pinchart

[permalink] [raw]
Subject: [PATCH v2] class: Free the class private data in class_release

Fix a memory leak by freeing the memory allocated in __class_register
for the class private data.

Signed-off-by: Laurent Pinchart <[email protected]>
---
drivers/base/class.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 161746d..6e2c3b0 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -59,6 +59,8 @@ static void class_release(struct kobject *kobj)
else
pr_debug("class '%s' does not have a release() function, "
"be careful\n", class->name);
+
+ kfree(cp);
}

static struct sysfs_ops class_sysfs_ops = {
--
1.6.4.4

2010-02-10 16:06:37

by Artem Bityutskiy

[permalink] [raw]
Subject: Re: [PATCH v2] class: Free the class private data in class_release

On Wed, 2010-02-10 at 13:32 +0100, ext Laurent Pinchart wrote:
> Fix a memory leak by freeing the memory allocated in __class_register
> for the class private data.
>
> Signed-off-by: Laurent Pinchart <[email protected]>

Acked-by: Artem Bityutskiy <[email protected]>

Thanks for finding this. For reference, this was spotted with help of
the great kmemleak tool.

--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

2010-02-12 07:17:55

by Artem Bityutskiy

[permalink] [raw]
Subject: Re: [PATCH v2] class: Free the class private data in class_release

On Wed, 2010-02-10 at 13:32 +0100, Laurent Pinchart wrote:
> Fix a memory leak by freeing the memory allocated in __class_register
> for the class private data.
>
> Signed-off-by: Laurent Pinchart <[email protected]>
> ---
> drivers/base/class.c | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/base/class.c b/drivers/base/class.c
> index 161746d..6e2c3b0 100644
> --- a/drivers/base/class.c
> +++ b/drivers/base/class.c
> @@ -59,6 +59,8 @@ static void class_release(struct kobject *kobj)
> else
> pr_debug("class '%s' does not have a release() function, "
> "be careful\n", class->name);
> +
> + kfree(cp);
> }
>
> static struct sysfs_ops class_sysfs_ops = {

This looks like 2.6.33 material for me. CC-ing Andrew.

--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

2010-02-12 15:36:04

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH v2] class: Free the class private data in class_release

On Fri, Feb 12, 2010 at 09:16:58AM +0200, Artem Bityutskiy wrote:
> On Wed, 2010-02-10 at 13:32 +0100, Laurent Pinchart wrote:
> > Fix a memory leak by freeing the memory allocated in __class_register
> > for the class private data.
> >
> > Signed-off-by: Laurent Pinchart <[email protected]>
> > ---
> > drivers/base/class.c | 2 ++
> > 1 files changed, 2 insertions(+), 0 deletions(-)
> >
> > diff --git a/drivers/base/class.c b/drivers/base/class.c
> > index 161746d..6e2c3b0 100644
> > --- a/drivers/base/class.c
> > +++ b/drivers/base/class.c
> > @@ -59,6 +59,8 @@ static void class_release(struct kobject *kobj)
> > else
> > pr_debug("class '%s' does not have a release() function, "
> > "be careful\n", class->name);
> > +
> > + kfree(cp);
> > }
> >
> > static struct sysfs_ops class_sysfs_ops = {
>
> This looks like 2.6.33 material for me. CC-ing Andrew.

Heh, I can handle .33 stuff just fine :)

thanks,

greg k-h