Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1897821pxk; Tue, 1 Sep 2020 10:17:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvHsUjlEcHMZS8s/im0eoJQrORh3wu7RLt5kxuY0kKlyGPEJGaXrpVamAWMBoJSsab/1PS X-Received: by 2002:a50:a165:: with SMTP id 92mr2806171edj.320.1598980650715; Tue, 01 Sep 2020 10:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598980650; cv=none; d=google.com; s=arc-20160816; b=tDpTtVUMKGoqoHHC3Em55QZnL48jPcUdN+QNOBN9gEe2wKa6rh2JUkJjidpuxKiWqW w29kgcJ+M1+oXoEIEDWmjvCCle9heVL6DG+62f1FvTXSAt+DXWIzjZFVT2BSp4935n6L 8vCLLkspaC1D0t3stZ0fQh+3uDozCn29XoXJS8GxYolBtds3GTCLxnShrRWVlDHjH8Vj b0NNtqfh/mG4Os9xdhnu5mnsA0LECcmC9A/2pREdFE+gIhrpXe/QAUe6IIqptHWW/q9s lc2evu4GIUlzawOAtysXyG3jA1BEJT95Mu7/H43vhlZJJ9ULkLYMkGC7YOYS2jgODA1I IZeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DFP/8QCHK1jaQZ800/6iYI2cQNaS6Gy3K7tvS33Kmds=; b=ydjDLhW4eZBf88yUw0l1L2QHX7MxxDDoAwfV1QiD3dz/VM2QtXtCatj+Rui/Q5/qDb 0TwtInEAX/D4sDwM7j5UAXMgv59KaQLv3YgftrP2kGXVPfCdNDLbgdSBWM5cb1r6A2hz UFdaSjnsjFSRM9ZSxfRhkC+KjagsQdhzqRBBfyihJxkBjqx6b5pzelj8B61L0dIEiZ0x sA5qKqnck1poHszLcnRJVu7NQ+MxPtf4vVanhvY8/zaX+PYSQ/EkqLcjwxDSrfWimbag 0NFcd9IY3Rvz9hCkHr/LObzJDFNLoOrADof+Qym0amy23tVDmoRxVQEyO6qycVKW4QEr UIgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oE9L+S8a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si1026883ejo.309.2020.09.01.10.17.06; Tue, 01 Sep 2020 10:17:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oE9L+S8a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732338AbgIARQZ (ORCPT + 99 others); Tue, 1 Sep 2020 13:16:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:58330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729049AbgIAPOb (ORCPT ); Tue, 1 Sep 2020 11:14:31 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 29F02214D8; Tue, 1 Sep 2020 15:14:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973271; bh=NZVOiuzSBZakKmTHz5OjTIZ8cTQyyV3gE5QGmIXA1B4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oE9L+S8aX3eZVrfsebOZkh1c2F9S3wNdHbKnW8dKdT6uqGSdYrcmJrZG0vLVkXeGk Bwmk/XwJq4rQGcZ09JbCdIQAl4grjW51sYMv1d7PLcIuOkhxOL/BpfDcshPs1jhK3V QBJ5u+fnzVLVk+SB5zsDnOWubVsLGdLWSIpCu4kM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qiushi Wu , Felix Kuehling , Alex Deucher , Sasha Levin Subject: [PATCH 4.9 13/78] drm/amdkfd: Fix reference count leaks. Date: Tue, 1 Sep 2020 17:09:49 +0200 Message-Id: <20200901150925.397951237@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150924.680106554@linuxfoundation.org> References: <20200901150924.680106554@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qiushi Wu [ Upstream commit 20eca0123a35305e38b344d571cf32768854168c ] 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 Reviewed-by: Felix Kuehling Signed-off-by: Felix Kuehling Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- 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 8c6e47c5507fb..74221e096855d 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c @@ -841,8 +841,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) @@ -885,8 +887,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; @@ -904,8 +908,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; @@ -923,8 +929,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; @@ -976,8 +984,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); -- 2.25.1