diff mbox series

drm/amdkfd: Fix reference count leaks.

Message ID 20200613193226.21531-1-wu000273@umn.edu (mailing list archive)
State New, archived
Headers show
Series drm/amdkfd: Fix reference count leaks. | expand

Commit Message

wu000273@umn.edu June 13, 2020, 7:32 p.m. UTC
From: Qiushi Wu <wu000273@umn.edu>

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object.

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Comments

Felix Kuehling June 15, 2020, 11:57 p.m. UTC | #1
On 2020-06-13 15:32, wu000273@umn.edu wrote:
> From: Qiushi Wu <wu000273@umn.edu>
>
> kobject_init_and_add() takes reference even when it fails.
> If this function returns an error, kobject_put() must be called to
> properly clean up the memory associated with the object.
>
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>

Thank you. The patch is

Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>

I'm applying the patch to our amd-staging-drm-next branch.

Regards,
   Felix


> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 20 +++++++++++++++-----
>   1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> index bb77f7af2b6d..dc3c4149f860 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> @@ -632,8 +632,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
>   
>   	ret = kobject_init_and_add(dev->kobj_node, &node_type,
>   			sys_props.kobj_nodes, "%d", id);
> -	if (ret < 0)
> +	if (ret < 0) {
> +		kobject_put(dev->kobj_node);
>   		return ret;
> +	}
>   
>   	dev->kobj_mem = kobject_create_and_add("mem_banks", dev->kobj_node);
>   	if (!dev->kobj_mem)
> @@ -680,8 +682,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
>   			return -ENOMEM;
>   		ret = kobject_init_and_add(mem->kobj, &mem_type,
>   				dev->kobj_mem, "%d", i);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			kobject_put(mem->kobj);
>   			return ret;
> +		}
>   
>   		mem->attr.name = "properties";
>   		mem->attr.mode = KFD_SYSFS_FILE_MODE;
> @@ -699,8 +703,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
>   			return -ENOMEM;
>   		ret = kobject_init_and_add(cache->kobj, &cache_type,
>   				dev->kobj_cache, "%d", i);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			kobject_put(cache->kobj);
>   			return ret;
> +		}
>   
>   		cache->attr.name = "properties";
>   		cache->attr.mode = KFD_SYSFS_FILE_MODE;
> @@ -718,8 +724,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
>   			return -ENOMEM;
>   		ret = kobject_init_and_add(iolink->kobj, &iolink_type,
>   				dev->kobj_iolink, "%d", i);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			kobject_put(iolink->kobj);
>   			return ret;
> +		}
>   
>   		iolink->attr.name = "properties";
>   		iolink->attr.mode = KFD_SYSFS_FILE_MODE;
> @@ -798,8 +806,10 @@ static int kfd_topology_update_sysfs(void)
>   		ret = kobject_init_and_add(sys_props.kobj_topology,
>   				&sysprops_type,  &kfd_device->kobj,
>   				"topology");
> -		if (ret < 0)
> +		if (ret < 0) {
> +			kobject_put(sys_props.kobj_topology);
>   			return ret;
> +		}
>   
>   		sys_props.kobj_nodes = kobject_create_and_add("nodes",
>   				sys_props.kobj_topology);
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index bb77f7af2b6d..dc3c4149f860 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -632,8 +632,10 @@  static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
 
 	ret = kobject_init_and_add(dev->kobj_node, &node_type,
 			sys_props.kobj_nodes, "%d", id);
-	if (ret < 0)
+	if (ret < 0) {
+		kobject_put(dev->kobj_node);
 		return ret;
+	}
 
 	dev->kobj_mem = kobject_create_and_add("mem_banks", dev->kobj_node);
 	if (!dev->kobj_mem)
@@ -680,8 +682,10 @@  static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
 			return -ENOMEM;
 		ret = kobject_init_and_add(mem->kobj, &mem_type,
 				dev->kobj_mem, "%d", i);
-		if (ret < 0)
+		if (ret < 0) {
+			kobject_put(mem->kobj);
 			return ret;
+		}
 
 		mem->attr.name = "properties";
 		mem->attr.mode = KFD_SYSFS_FILE_MODE;
@@ -699,8 +703,10 @@  static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
 			return -ENOMEM;
 		ret = kobject_init_and_add(cache->kobj, &cache_type,
 				dev->kobj_cache, "%d", i);
-		if (ret < 0)
+		if (ret < 0) {
+			kobject_put(cache->kobj);
 			return ret;
+		}
 
 		cache->attr.name = "properties";
 		cache->attr.mode = KFD_SYSFS_FILE_MODE;
@@ -718,8 +724,10 @@  static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
 			return -ENOMEM;
 		ret = kobject_init_and_add(iolink->kobj, &iolink_type,
 				dev->kobj_iolink, "%d", i);
-		if (ret < 0)
+		if (ret < 0) {
+			kobject_put(iolink->kobj);
 			return ret;
+		}
 
 		iolink->attr.name = "properties";
 		iolink->attr.mode = KFD_SYSFS_FILE_MODE;
@@ -798,8 +806,10 @@  static int kfd_topology_update_sysfs(void)
 		ret = kobject_init_and_add(sys_props.kobj_topology,
 				&sysprops_type,  &kfd_device->kobj,
 				"topology");
-		if (ret < 0)
+		if (ret < 0) {
+			kobject_put(sys_props.kobj_topology);
 			return ret;
+		}
 
 		sys_props.kobj_nodes = kobject_create_and_add("nodes",
 				sys_props.kobj_topology);