Skip to content

Commit e3c5ac6

Browse files
Ma Kegregkh
authored andcommitted
sparc: fix error handling in scan_one_device()
commit 302c041 upstream. Once of_device_register() failed, we should call put_device() to decrement reference count for cleanup. Or it could cause memory leak. So fix this by calling put_device(), then the name can be freed in kobject_cleanup(). Calling path: of_device_register() -> of_device_add() -> device_add(). As comment of device_add() says, 'if device_add() succeeds, you should call device_del() when you want to get rid of it. If device_add() has not succeeded, use only put_device() to drop the reference count'. Found by code review. Cc: stable@vger.kernel.org Fixes: cf44bbc ("[SPARC]: Beginnings of generic of_device framework.") Signed-off-by: Ma Ke <make24@iscas.ac.cn> Reviewed-by: Andreas Larsson <andreas@gaisler.com> Signed-off-by: Andreas Larsson <andreas@gaisler.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9632dd9 commit e3c5ac6

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

arch/sparc/kernel/of_device_32.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
387387

388388
if (of_device_register(op)) {
389389
printk("%pOF: Could not register of device.\n", dp);
390+
put_device(&op->dev);
390391
kfree(op);
391392
op = NULL;
392393
}

arch/sparc/kernel/of_device_64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
677677

678678
if (of_device_register(op)) {
679679
printk("%pOF: Could not register of device.\n", dp);
680+
put_device(&op->dev);
680681
kfree(op);
681682
op = NULL;
682683
}

0 commit comments

Comments
 (0)