Commit 7a9a3656 authored by Yong Zhao's avatar Yong Zhao Committed by Greg Kroah-Hartman

drm/amdkfd: Fix memory leaks in kfd topology


[ Upstream commit 5108d768 ]

Kobject created using kobject_create_and_add() can be freed using
kobject_put() when there is no referenece any more. However,
kobject memory allocated with kzalloc() has to set up a release
callback in order to free it when the counter decreases to 0.
Otherwise it causes memory leak.
Signed-off-by: default avatarYong Zhao <yong.zhao@amd.com>
Signed-off-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent eaea613f
...@@ -519,11 +519,17 @@ static ssize_t sysprops_show(struct kobject *kobj, struct attribute *attr, ...@@ -519,11 +519,17 @@ static ssize_t sysprops_show(struct kobject *kobj, struct attribute *attr,
return ret; return ret;
} }
static void kfd_topology_kobj_release(struct kobject *kobj)
{
kfree(kobj);
}
static const struct sysfs_ops sysprops_ops = { static const struct sysfs_ops sysprops_ops = {
.show = sysprops_show, .show = sysprops_show,
}; };
static struct kobj_type sysprops_type = { static struct kobj_type sysprops_type = {
.release = kfd_topology_kobj_release,
.sysfs_ops = &sysprops_ops, .sysfs_ops = &sysprops_ops,
}; };
...@@ -559,6 +565,7 @@ static const struct sysfs_ops iolink_ops = { ...@@ -559,6 +565,7 @@ static const struct sysfs_ops iolink_ops = {
}; };
static struct kobj_type iolink_type = { static struct kobj_type iolink_type = {
.release = kfd_topology_kobj_release,
.sysfs_ops = &iolink_ops, .sysfs_ops = &iolink_ops,
}; };
...@@ -586,6 +593,7 @@ static const struct sysfs_ops mem_ops = { ...@@ -586,6 +593,7 @@ static const struct sysfs_ops mem_ops = {
}; };
static struct kobj_type mem_type = { static struct kobj_type mem_type = {
.release = kfd_topology_kobj_release,
.sysfs_ops = &mem_ops, .sysfs_ops = &mem_ops,
}; };
...@@ -625,6 +633,7 @@ static const struct sysfs_ops cache_ops = { ...@@ -625,6 +633,7 @@ static const struct sysfs_ops cache_ops = {
}; };
static struct kobj_type cache_type = { static struct kobj_type cache_type = {
.release = kfd_topology_kobj_release,
.sysfs_ops = &cache_ops, .sysfs_ops = &cache_ops,
}; };
...@@ -747,6 +756,7 @@ static const struct sysfs_ops node_ops = { ...@@ -747,6 +756,7 @@ static const struct sysfs_ops node_ops = {
}; };
static struct kobj_type node_type = { static struct kobj_type node_type = {
.release = kfd_topology_kobj_release,
.sysfs_ops = &node_ops, .sysfs_ops = &node_ops,
}; };
......
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