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>
Sat, 10 Apr 2021 09:10:21 +0000 (11:10 +0200)
commit4ce535ec0084f0d712317cb99d383cad3288e713
tree95156c8b8fdb08224acfdbec7518fa4433a7ddc9
parentb4104180a2efb85f55e1ba1407885c9421970338
node: fix device cleanups in error handling code

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>
drivers/base/node.c