sparc: vio: Add refcount when a new reference is created
PATCH 1/1 sparc: vio: Add refcount when a new reference is created
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 <[email protected]>
--- arch/sparc/kernel/vio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/sparc/kernel/vio.c +7 -4
@@ -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 ; }
Signature · 1 line
2.25.1