driver-core: only call kfree() if memory was allocated
PATCH 1/1 driver-core: only call kfree() if memory was allocated
There are several cases where we could bail out of show_uevent() before kzalloc() is even called. In those cases we don't want to call kfree().
In addition the error handling of kzalloc() is now using the single point of exit as well.
--- drivers/base/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/base/core.c +6 -3
@@ -372,8 +372,10 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr, goto out; env =kzalloc (sizeof (struct kobj_uevent_env ),GFP_KERNEL ); -if (!env) -return -ENOMEM ; +if (!env) { + count = -ENOMEM ; + goto out; + }/* let the kset specific function add its keys */ retval = kset->uevent_ops->uevent (kset, &dev->kobj, env);
@@ -383,8 +385,9 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,/* copy keys to file */ for (i =0 ; i < env->envp_idx; i++) count +=sprintf (&buf[count],"%s\n" , env->envp[i]); -out: +out_free:kfree (env); +out:return count; }
Signature · 1 line
1.7.10.4
Greg KH
maintainerQuoted 3 lines · Andreas Platschek
There are several cases where we could bail out of
show_uevent()beforekzalloc()is even called. In those cases we don't want to callkfree().
Why not? It's totally safe to do that.
Quoted 2 lines
In addition the error handling of
kzalloc()is now using the single point of exit as well.
We had the single point of exit to start with, there's no change made there.
Sorry, but I'm not going to take this patch, it's not needed.
thanks,
greg k-h
Greg KH
maintainerQuoted 5 lines · Greg KH
Quoted 3 lines · Andreas Platschek
There are several cases where we could bail out of
show_uevent()beforekzalloc()is even called. In those cases we don't want to callkfree().
Quoted 7 lines
Why not? It's totally safe to do that.
Quoted 2 lines
In addition the error handling of
kzalloc()is now using the single point of exit as well.We had the single point of exit to start with, there's no change made there.
Oops, no, you are correct about that one, but it's not really a big deal for such a small function.
greg k-h