mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] driver core: bus: Free the kobject.name if kset_register fails
@ 2015-06-09  9:05 Chen Lin Z
  2015-08-06  0:01 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Lin Z @ 2015-06-09  9:05 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, bo.he, yanmin_zhang, Chen Lin Z

if register two bus with the same name, kset_register will fail.
it need free kobject.name, otherwise there is a memory leak.

Signed-off-by: Chen Lin Z <lin.z.chen@intel.com>
---
 drivers/base/bus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 79bc203..9375048 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -894,8 +894,10 @@ int bus_register(struct bus_type *bus)
 	priv->drivers_autoprobe = 1;
 
 	retval = kset_register(&priv->subsys);
-	if (retval)
+	if (retval) {
+		kfree(priv->subsys.kobj.name);
 		goto out;
+	}
 
 	retval = bus_create_file(bus, &bus_attr_uevent);
 	if (retval)
-- 
1.9.1


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

* Re: [PATCH] driver core: bus: Free the kobject.name if kset_register fails
  2015-06-09  9:05 [PATCH] driver core: bus: Free the kobject.name if kset_register fails Chen Lin Z
@ 2015-08-06  0:01 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2015-08-06  0:01 UTC (permalink / raw)
  To: Chen Lin Z; +Cc: linux-kernel, bo.he, yanmin_zhang

On Tue, Jun 09, 2015 at 05:05:21PM +0800, Chen Lin Z wrote:
> if register two bus with the same name, kset_register will fail.
> it need free kobject.name, otherwise there is a memory leak.
> 
> Signed-off-by: Chen Lin Z <lin.z.chen@intel.com>
> ---
>  drivers/base/bus.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index 79bc203..9375048 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -894,8 +894,10 @@ int bus_register(struct bus_type *bus)
>  	priv->drivers_autoprobe = 1;
>  
>  	retval = kset_register(&priv->subsys);
> -	if (retval)
> +	if (retval) {
> +		kfree(priv->subsys.kobj.name);

This doesn't solve the problem properly, as all of the other error paths
also need to free this memory.

And I really hate to poke around this "deep" into the kobject core, but
I understand it's needed here :(

thanks,

greg k-h

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

end of thread, other threads:[~2015-08-06  0:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09  9:05 [PATCH] driver core: bus: Free the kobject.name if kset_register fails Chen Lin Z
2015-08-06  0:01 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®