aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorJesper Juhl <jesper.juhl@gmail.com>2008-03-28 17:16:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-03-28 17:45:23 -0400
commitd478376cb0dc9ab16a2b6e02fd8cd1174e724c64 (patch)
treefda590df6ece65517db78c3434898640f56c60ee /drivers/base
parent4cdc1d1fa5c5ac14dc21be19832f02fd0b83867e (diff)
driver core: fix small mem leak in driver_add_kobj()
The Coverity checker spotted that we leak the storage allocated to 'name' in int driver_add_kobj(). The leak looks legit to me - this is the code : int driver_add_kobj(struct device_driver *drv, struct kobject *kobj, const char *fmt, ...) { va_list args; char *name; int ret; va_start(args, fmt); name = kvasprintf(GFP_KERNEL, fmt, args); ^^^^^^^^ This dynamically allocates space... va_end(args); if (!name) return -ENOMEM; return kobject_add(kobj, &drv->p->kobj, "%s", name); ^^^^^^^^ This neglects to free the space allocated } Inside kobject_add() a copy of 'name' will be made and used. As far as I can see, Coverity is correct in flagging this as a leak, but I'd like some configmation before the patch is applied. This should fix it. Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com> Cc: Greg KH <greg@kroah.com> Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/driver.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index bf31a0170a48..9a6537f14401 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -133,6 +133,7 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
133{ 133{
134 va_list args; 134 va_list args;
135 char *name; 135 char *name;
136 int ret;
136 137
137 va_start(args, fmt); 138 va_start(args, fmt);
138 name = kvasprintf(GFP_KERNEL, fmt, args); 139 name = kvasprintf(GFP_KERNEL, fmt, args);
@@ -141,7 +142,9 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
141 if (!name) 142 if (!name)
142 return -ENOMEM; 143 return -ENOMEM;
143 144
144 return kobject_add(kobj, &drv->p->kobj, "%s", name); 145 ret = kobject_add(kobj, &drv->p->kobj, "%s", name);
146 kfree(name);
147 return ret;
145} 148}
146EXPORT_SYMBOL_GPL(driver_add_kobj); 149EXPORT_SYMBOL_GPL(driver_add_kobj);
147 150