Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1885158pxk; Tue, 1 Sep 2020 10:01:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLPYtkf7ju/cmFA87wM/6KFUB7aSjvFslpWzr5ayqhoRGKrzQJ/E9uk5qgfEKmZ8wndh5c X-Received: by 2002:a17:906:4c51:: with SMTP id d17mr2380004ejw.28.1598979682916; Tue, 01 Sep 2020 10:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598979682; cv=none; d=google.com; s=arc-20160816; b=jpmPUss2KppOwBgz11iMsEPDkwW/uUrff0ZFSpzVlZ2wajCZ+4q1OAgSNII3K4qUDD 4Py53WgBsuFN/q2UpvZ77xLxcsWOHh8dqzbIYlJHyJaIPZjGqzc8AHLGyyfy3c9Mjp/e K1qfc7XW57bTeLuaUUi1e2oFWT3j92UMq/VXnvmWu2jqsUXswuHPMuOTsJ2ipJVlxujy O5AE8r/fcsxEX1sL3MvSL7u+V2QTLscCiL0xHqQcVoZ+d6YjUZXtz8lsBdoHjNFzeUxD CH3sJnBcEWgObT75VqicKoLToRqsAPiYeJPitqfVTOmrbXVCG8Gc2phCiWy79KcCRsyP vBRg== 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=HYIBwuv4Ze5Z612JysZts2cAIrOlaoHJqKi4aCRXvvs=; b=gZI7y9Ha0ORyT8/53L63V1RH9LTGLG8/J+mz5gAHIbQWsFzJnF1ibWgP6dIMq/S1KT ebRE+W0hvdjSpcwZKOPJmcKTvltefbaX4oeHNHdIVICjp6XN4ijADhCzBHC7icar/9nI z8uNhO/R8Duj1cDYeqbsxRtEXTuEtKIZ4UF0W1OGOiyWMV8nbbU6de4+N1zqzMqZSCxw JC2R4TeG+RdLAgdkZe0eu2+IeLJE3dvPd2O04J6nZFiAj5xYte+zjcEqLMfgRLU28k9J 3WRF9GSkiIlhLW3AWi9EkC94JFJpiwGA404YYB+moRg+qBdc7wgUhZOOgDsbX51FyzNK CecQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L0TBZ5tm; 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 ce15si355600edb.291.2020.09.01.10.00.59; Tue, 01 Sep 2020 10:01:22 -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=L0TBZ5tm; 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 S1732417AbgIAQ7R (ORCPT + 99 others); Tue, 1 Sep 2020 12:59:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:43272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729719AbgIAPWD (ORCPT ); Tue, 1 Sep 2020 11:22:03 -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 47CAF206FA; Tue, 1 Sep 2020 15:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973722; bh=kXMZ9l08Jah4khEVfm/oqIOOPDumgTMeD3tiEwkvODU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0TBZ5tmwXkvcTkh8+x3zPrhFoVvNAc+ra2uND7aoU66Ojqbj12uYE17B7fQ83m0D YZPT/d3mP8xKDBpM+22RmWyTJYQ8k2iTI0vAdLnt68W+APr0u4cUi7J9SdKTMuuDav lAWqqNN0REtX9gvSudoVpdvXsma6sam91uxBg8Ts= 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.19 020/125] drm/amdkfd: Fix reference count leaks. Date: Tue, 1 Sep 2020 17:09:35 +0200 Message-Id: <20200901150935.555762687@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150934.576210879@linuxfoundation.org> References: <20200901150934.576210879@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 0805c423a5ce0..5cf499a07806a 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c @@ -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, 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) @@ -640,8 +642,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; @@ -659,8 +663,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; @@ -678,8 +684,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; @@ -759,8 +767,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