aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorYong Zhao <yong.zhao@amd.com>2017-12-08 23:08:48 -0500
committerOded Gabbay <oded.gabbay@gmail.com>2017-12-08 23:08:48 -0500
commit5108d768408abc80e4e8d99f5b406a73cb04056b (patch)
tree19942f9b6191eaa225292b267415c236b4bf66fb /drivers
parentd63f0ba27a3ee33211de4ec7f2c4287a03492cb2 (diff)
drm/amdkfd: Fix memory leaks in kfd topology
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: Yong Zhao <yong.zhao@amd.com> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com> Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com> Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_topology.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index b614746c2523..9b9824f97de5 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -501,11 +501,17 @@ static ssize_t sysprops_show(struct kobject *kobj, struct attribute *attr,
501 return ret; 501 return ret;
502} 502}
503 503
504static void kfd_topology_kobj_release(struct kobject *kobj)
505{
506 kfree(kobj);
507}
508
504static const struct sysfs_ops sysprops_ops = { 509static const struct sysfs_ops sysprops_ops = {
505 .show = sysprops_show, 510 .show = sysprops_show,
506}; 511};
507 512
508static struct kobj_type sysprops_type = { 513static struct kobj_type sysprops_type = {
514 .release = kfd_topology_kobj_release,
509 .sysfs_ops = &sysprops_ops, 515 .sysfs_ops = &sysprops_ops,
510}; 516};
511 517
@@ -541,6 +547,7 @@ static const struct sysfs_ops iolink_ops = {
541}; 547};
542 548
543static struct kobj_type iolink_type = { 549static struct kobj_type iolink_type = {
550 .release = kfd_topology_kobj_release,
544 .sysfs_ops = &iolink_ops, 551 .sysfs_ops = &iolink_ops,
545}; 552};
546 553
@@ -568,6 +575,7 @@ static const struct sysfs_ops mem_ops = {
568}; 575};
569 576
570static struct kobj_type mem_type = { 577static struct kobj_type mem_type = {
578 .release = kfd_topology_kobj_release,
571 .sysfs_ops = &mem_ops, 579 .sysfs_ops = &mem_ops,
572}; 580};
573 581
@@ -607,6 +615,7 @@ static const struct sysfs_ops cache_ops = {
607}; 615};
608 616
609static struct kobj_type cache_type = { 617static struct kobj_type cache_type = {
618 .release = kfd_topology_kobj_release,
610 .sysfs_ops = &cache_ops, 619 .sysfs_ops = &cache_ops,
611}; 620};
612 621
@@ -729,6 +738,7 @@ static const struct sysfs_ops node_ops = {
729}; 738};
730 739
731static struct kobj_type node_type = { 740static struct kobj_type node_type = {
741 .release = kfd_topology_kobj_release,
732 .sysfs_ops = &node_ops, 742 .sysfs_ops = &node_ops,
733}; 743};
734 744