driver core: node: use put_device() if device_register fail
authorArvind Yadav <arvind.yadav.cs@gmail.com>
Sun, 11 Mar 2018 05:55:50 +0000 (11:25 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Mar 2018 13:37:04 +0000 (14:37 +0100)
if device_register() returned an error! Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/node.c

index ee090ab9171c269dfaeade5f1c1c4e5584566e70..c5f81fc621ac27d60842cf7a3fc2b786076ef474 100644 (file)
@@ -315,7 +315,9 @@ static int register_node(struct node *node, int num)
        node->dev.groups = node_dev_groups;
        error = device_register(&node->dev);
 
-       if (!error){
+       if (error)
+               put_device(&node->dev);
+       else {
                hugetlb_register_node(node);
 
                compaction_register_node(node);