Commit 3572290d authored by Ma Ke's avatar Ma Ke Committed by Greg Kroah-Hartman
Browse files

sparc: fix error handling in scan_one_device()



commit 302c0411 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: cf44bbc2 ("[SPARC]: Beginnings of generic of_device framework.")
Signed-off-by: default avatarMa Ke <make24@iscas.ac.cn>
Reviewed-by: default avatarAndreas Larsson <andreas@gaisler.com>
Signed-off-by: default avatarAndreas Larsson <andreas@gaisler.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 612d10ce
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment