In vio_create_one(), when a new reference of 'device_node' is created into 'vdev->dp', we should call of_node_get(). Besides, we should also call of_node_put() before the 'vdev' is freed in fail path. NOTE: As the for_each_child_of_node() will automatically increase and decrease the refcount, it needs no more refcounting for the new reference. Signed-off-by: Liang He <windhl@xxxxxxx> --- arch/sparc/kernel/vio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/sparc/kernel/vio.c b/arch/sparc/kernel/vio.c index 01122a208f94..10441a7ef976 100644 --- a/arch/sparc/kernel/vio.c +++ b/arch/sparc/kernel/vio.c @@ -362,16 +362,17 @@ static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp, vdev->dev.release = vio_dev_release; if (parent == NULL) { - dp = cdev_node; + vdev->dp = of_node_get(cdev_node); } else if (to_vio_dev(parent) == root_vdev) { for_each_child_of_node(cdev_node, dp) { - if (of_node_is_type(dp, type)) + if (of_node_is_type(dp, type)) { + vdev->dp = dp; break; + } } } else { - dp = to_vio_dev(parent)->dp; + vdev->dp = of_node_get(to_vio_dev(parent)->dp); } - vdev->dp = dp; /* * node_name is NULL for the parent/channel-devices node and @@ -386,6 +387,7 @@ static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp, if (err) { pr_err("VIO: Could not get MD node info %s, err=%d\n", dev_name(&vdev->dev), err); + of_node_put(vdev->dp); kfree(vdev); return NULL; } @@ -398,6 +400,7 @@ static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp, if (err) { printk(KERN_ERR "VIO: Could not register device %s, err=%d\n", dev_name(&vdev->dev), err); + of_node_put(vdev->dp); put_device(&vdev->dev); return NULL; } -- 2.25.1