Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp148268pxa; Wed, 26 Aug 2020 07:08:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ6CN9XYXF8JL8JohR/Y/p2K4xX1nv2W4vDSGBV8jHe4WY+JCn4sD8o0fO5WOzBSyvp9bJ X-Received: by 2002:a05:6402:339:: with SMTP id q25mr14437867edw.268.1598450891038; Wed, 26 Aug 2020 07:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598450891; cv=none; d=google.com; s=arc-20160816; b=i+jo3AYxJhTNntgN4JCI+CpxX1ctv5VF2GGMBgigH9/3h4W8D6PxGd6DT4i3dsMto9 R8ekoIforLuNuaZnvloHeqp+OdTgH5jQspeqCC2x1zJFKIUitb43IT5OTrqEGMpdwVX6 dZIJdDN58y62uoVZT8FjdhrkUyH33WdmzrEeBpMimKCBCPARfBq2GzooNH7Pfgat0ge2 liYW1TJlm8zAYKYmO5UxKu+lX7OiO539v6sgJyjDKPRVrnp7fRAI54e7hYfr0U3AKwKD mb7NLq2K3BmzFArYZesw7ex1nhGkBLVuNqGf0JgRvz6X6HNmMfs0P4y9kBETezT/uxmN vRiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=joG1segtUUxBoAl/Zfa0US8KH2zAVKZdSKM3cOb9Z8w=; b=neU9SwG7zMqyDEvmN3VH9vjxA0zFlbfq+2L93ZJDnPIPmAvBiR3ciVhh5voyO/B74f cnI33f0v2xk0vsPFKYzLHfyQWHPB7MeaUn7UWy5n7tQUa53KkSHJf9h9TpfQgWLLyR0v sXNYGmuZy+qOrX1TDOCrgAV726ZSeoXitw4s0np7oL26mLhQRPlYVUf0HshpZuMLXZjy dwFaQ77sqpLmmXTTQeO5kZuSy4oIujRXfkY+CJDXR7km1dVSYoWOYzynfaKRTpa4bePY xD+n361ftHHH1wpWEk+URwKmyRzRxmJoWsNaLESzdtIKhGc7kxfFv4gaxqnd7SUwOKhQ mBIQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si1443360edw.591.2020.08.26.07.07.46; Wed, 26 Aug 2020 07:08:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727062AbgHZIhR (ORCPT + 99 others); Wed, 26 Aug 2020 04:37:17 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:36550 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727045AbgHZIhQ (ORCPT ); Wed, 26 Aug 2020 04:37:16 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id AFA9991A271F0DDD8FA3; Wed, 26 Aug 2020 16:37:10 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Wed, 26 Aug 2020 16:37:00 +0800 From: Hanjun Guo To: Felix Kuehling , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Airlie , Daniel Vetter CC: , Hanjun Guo Subject: [PATCH v2 2/2] drm/amdkfd: Put ACPI table after using it Date: Wed, 26 Aug 2020 16:29:16 +0800 Message-ID: <1598430556-18788-2-git-send-email-guohanjun@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1598430556-18788-1-git-send-email-guohanjun@huawei.com> References: <1598430556-18788-1-git-send-email-guohanjun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The acpi_get_table() should be coupled with acpi_put_table() if the mapped table is not used at runtime to release the table mapping which can prevent the memory leak. In kfd_create_crat_image_acpi(), crat_table is copied to pcrat_image, and in kfd_create_vcrat_image_cpu(), the acpi_table is only used to get the OEM information, so those two table mappings need to be released after using it. Fixes: 174de876d6d0 ("drm/amdkfd: Group up CRAT related functions") Fixes: 520b8fb755cc ("drm/amdkfd: Add topology support for CPUs") Signed-off-by: Hanjun Guo --- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c index ed77b109..c3f3ffb6 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c @@ -758,6 +758,7 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size) struct acpi_table_header *crat_table; acpi_status status; void *pcrat_image; + int rc = 0; if (!crat_image) return -EINVAL; @@ -782,13 +783,16 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size) } pcrat_image = kmemdup(crat_table, crat_table->length, GFP_KERNEL); - if (!pcrat_image) - return -ENOMEM; + if (!pcrat_image) { + rc = -ENOMEM; + goto out; + } *crat_image = pcrat_image; *size = crat_table->length; - - return 0; +out: + acpi_put_table(crat_table); + return rc; } /* Memory required to create Virtual CRAT. @@ -972,6 +976,7 @@ static int kfd_create_vcrat_image_cpu(void *pcrat_image, size_t *size) CRAT_OEMID_LENGTH); memcpy(crat_table->oem_table_id, acpi_table->oem_table_id, CRAT_OEMTABLEID_LENGTH); + acpi_put_table(acpi_table); } crat_table->total_entries = 0; crat_table->num_domains = 0; -- 1.7.12.4