node: fix device cleanups in error handling code
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 9 Apr 2021 11:01:57 +0000 (14:01 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 07:50:19 +0000 (09:50 +0200)
commitc703ef8289dce715a012d038412030b49bfbf049
tree51388eb3aac1ce7da13100efb8d5a0a6c9b23ed9
parent190a2f24aed6546b98469b413306dc73d201df06
node: fix device cleanups in error handling code

[ Upstream commit 4ce535ec0084f0d712317cb99d383cad3288e713 ]

We can't use kfree() to free device managed resources so the kfree(dev)
is against the rules.

It's easier to write this code if we open code the device_register() as
a device_initialize() and device_add().  That way if dev_set_name() set
name fails we can call put_device() and it will clean up correctly.

Fixes: acc02a109b04 ("node: Add memory-side caching attributes")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YHA0JUra+F64+NpB@mwanda
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/base/node.c