Commit 74d20579 authored by Qiushi Wu's avatar Qiushi Wu Committed by Greg Kroah-Hartman

drm/amdkfd: Fix reference count leaks.

[ Upstream commit 20eca012 ]

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: default avatarQiushi Wu <wu000273@umn.edu>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 9c972381
...@@ -592,8 +592,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev, ...@@ -592,8 +592,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
ret = kobject_init_and_add(dev->kobj_node, &node_type, ret = kobject_init_and_add(dev->kobj_node, &node_type,
sys_props.kobj_nodes, "%d", id); sys_props.kobj_nodes, "%d", id);
if (ret < 0) if (ret < 0) {
kobject_put(dev->kobj_node);
return ret; return ret;
}
dev->kobj_mem = kobject_create_and_add("mem_banks", dev->kobj_node); dev->kobj_mem = kobject_create_and_add("mem_banks", dev->kobj_node);
if (!dev->kobj_mem) if (!dev->kobj_mem)
...@@ -640,8 +642,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev, ...@@ -640,8 +642,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
return -ENOMEM; return -ENOMEM;
ret = kobject_init_and_add(mem->kobj, &mem_type, ret = kobject_init_and_add(mem->kobj, &mem_type,
dev->kobj_mem, "%d", i); dev->kobj_mem, "%d", i);
if (ret < 0) if (ret < 0) {
kobject_put(mem->kobj);
return ret; return ret;
}
mem->attr.name = "properties"; mem->attr.name = "properties";
mem->attr.mode = KFD_SYSFS_FILE_MODE; mem->attr.mode = KFD_SYSFS_FILE_MODE;
...@@ -659,8 +663,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev, ...@@ -659,8 +663,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
return -ENOMEM; return -ENOMEM;
ret = kobject_init_and_add(cache->kobj, &cache_type, ret = kobject_init_and_add(cache->kobj, &cache_type,
dev->kobj_cache, "%d", i); dev->kobj_cache, "%d", i);
if (ret < 0) if (ret < 0) {
kobject_put(cache->kobj);
return ret; return ret;
}
cache->attr.name = "properties"; cache->attr.name = "properties";
cache->attr.mode = KFD_SYSFS_FILE_MODE; cache->attr.mode = KFD_SYSFS_FILE_MODE;
...@@ -678,8 +684,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev, ...@@ -678,8 +684,10 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,
return -ENOMEM; return -ENOMEM;
ret = kobject_init_and_add(iolink->kobj, &iolink_type, ret = kobject_init_and_add(iolink->kobj, &iolink_type,
dev->kobj_iolink, "%d", i); dev->kobj_iolink, "%d", i);
if (ret < 0) if (ret < 0) {
kobject_put(iolink->kobj);
return ret; return ret;
}
iolink->attr.name = "properties"; iolink->attr.name = "properties";
iolink->attr.mode = KFD_SYSFS_FILE_MODE; iolink->attr.mode = KFD_SYSFS_FILE_MODE;
...@@ -759,8 +767,10 @@ static int kfd_topology_update_sysfs(void) ...@@ -759,8 +767,10 @@ static int kfd_topology_update_sysfs(void)
ret = kobject_init_and_add(sys_props.kobj_topology, ret = kobject_init_and_add(sys_props.kobj_topology,
&sysprops_type, &kfd_device->kobj, &sysprops_type, &kfd_device->kobj,
"topology"); "topology");
if (ret < 0) if (ret < 0) {
kobject_put(sys_props.kobj_topology);
return ret; return ret;
}
sys_props.kobj_nodes = kobject_create_and_add("nodes", sys_props.kobj_nodes = kobject_create_and_add("nodes",
sys_props.kobj_topology); sys_props.kobj_topology);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment