aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/uio
diff options
context:
space:
mode:
authorCong Ding <dinggnu@gmail.com>2013-10-25 03:25:53 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-29 19:36:54 -0400
commit75f0aef6220dc1e73bed238e57b20544ef4f38ec (patch)
tree4e78ce7114059a8ed12f49c0293f12b11aebcb0e /drivers/uio
parent7c65e29250a3154cac18b527b6ccfc61f8f08c58 (diff)
uio: fix memory leak
we have to call kobject_put() to clean up the kobject after function kobject_init(), kobject_add(), or kobject_uevent() is called. Signed-off-by: Cong Ding <dinggnu@gmail.com> Acked-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/uio')
-rw-r--r--drivers/uio/uio.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 11d4e0a52579..c8e45add506e 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -288,13 +288,13 @@ static int uio_dev_add_attributes(struct uio_device *idev)
288 } 288 }
289 map = kzalloc(sizeof(*map), GFP_KERNEL); 289 map = kzalloc(sizeof(*map), GFP_KERNEL);
290 if (!map) 290 if (!map)
291 goto err_map; 291 goto err_map_kobj;
292 kobject_init(&map->kobj, &map_attr_type); 292 kobject_init(&map->kobj, &map_attr_type);
293 map->mem = mem; 293 map->mem = mem;
294 mem->map = map; 294 mem->map = map;
295 ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi); 295 ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi);
296 if (ret) 296 if (ret)
297 goto err_map; 297 goto err_map_kobj;
298 ret = kobject_uevent(&map->kobj, KOBJ_ADD); 298 ret = kobject_uevent(&map->kobj, KOBJ_ADD);
299 if (ret) 299 if (ret)
300 goto err_map; 300 goto err_map;
@@ -313,14 +313,14 @@ static int uio_dev_add_attributes(struct uio_device *idev)
313 } 313 }
314 portio = kzalloc(sizeof(*portio), GFP_KERNEL); 314 portio = kzalloc(sizeof(*portio), GFP_KERNEL);
315 if (!portio) 315 if (!portio)
316 goto err_portio; 316 goto err_portio_kobj;
317 kobject_init(&portio->kobj, &portio_attr_type); 317 kobject_init(&portio->kobj, &portio_attr_type);
318 portio->port = port; 318 portio->port = port;
319 port->portio = portio; 319 port->portio = portio;
320 ret = kobject_add(&portio->kobj, idev->portio_dir, 320 ret = kobject_add(&portio->kobj, idev->portio_dir,
321 "port%d", pi); 321 "port%d", pi);
322 if (ret) 322 if (ret)
323 goto err_portio; 323 goto err_portio_kobj;
324 ret = kobject_uevent(&portio->kobj, KOBJ_ADD); 324 ret = kobject_uevent(&portio->kobj, KOBJ_ADD);
325 if (ret) 325 if (ret)
326 goto err_portio; 326 goto err_portio;
@@ -329,14 +329,18 @@ static int uio_dev_add_attributes(struct uio_device *idev)
329 return 0; 329 return 0;
330 330
331err_portio: 331err_portio:
332 for (pi--; pi >= 0; pi--) { 332 pi--;
333err_portio_kobj:
334 for (; pi >= 0; pi--) {
333 port = &idev->info->port[pi]; 335 port = &idev->info->port[pi];
334 portio = port->portio; 336 portio = port->portio;
335 kobject_put(&portio->kobj); 337 kobject_put(&portio->kobj);
336 } 338 }
337 kobject_put(idev->portio_dir); 339 kobject_put(idev->portio_dir);
338err_map: 340err_map:
339 for (mi--; mi>=0; mi--) { 341 mi--;
342err_map_kobj:
343 for (; mi >= 0; mi--) {
340 mem = &idev->info->mem[mi]; 344 mem = &idev->info->mem[mi];
341 map = mem->map; 345 map = mem->map;
342 kobject_put(&map->kobj); 346 kobject_put(&map->kobj);