Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp850805pxb; Thu, 12 Nov 2020 19:24:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTd0PbHkGVQHq4z2suPS065uu+qOM52/QgxDoNTtcWof1reVnUIQA7fQlN9p3aBr3H/EZA X-Received: by 2002:a17:906:284b:: with SMTP id s11mr97851ejc.326.1605237859346; Thu, 12 Nov 2020 19:24:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605237859; cv=none; d=google.com; s=arc-20160816; b=G7SkRNeTH7KwfPnZGKFcNUDcc5d75IROW+kpOYMkMGYFiyQ3oZqc+ivN3teCgUqSzY QLu5IEPoUxZW9+43F66LuAI841YhUwWkqx7Jh/iSK2cMQAeXaYBmvDP/dHY/8eXTex0q dqhc1oW5KYAw6ZwW9bxXdQpt56FvY9QgIKSGQXoWI1plavjHXTtePJJ5NKQOGUDr8066 zwD6eVhdCIZYjMcjkdoFPGqt88JyDQ9PlWlP94tglsMCXD0xAKxyOb7PRpnkWWd9Qwqs 5LEdmRkTI3SsRwICPsZe5mzJEpykt9LsCXz28N/MXSkYWdwpUkittZ4asvEk34U8MYoH aI7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=aQS65vt2xayY/VcKE3Zmc8KKuGeMG7CE9YuvRpB7U20=; b=JG0pIRigPW7dhX2aFomX8RseOWC5NakHIL6Yq63iCsfCfGY7CVw1u1hNVEPk21wb5x yPfOn3srZNqObDRDAmhD4JhMprtCnl6neKd4F0drxIMUZsUgD+SEOsWRU/DJSq5L+KnM vJldTlQu8zYgKWfYJvUxpjGHmAh+hVYON9QPJ9evam6bXw0CWp/lUJ+k9dy5AG6mN+lH l0FVH5ji/GZQFtpGGhEPOpceXoL0cG6ZMJnwroNCyRVFpWJluztq8YMeUG2Cqv3j4l8s Kv24PbAvC1+m7p07u8CZ22pfpqFK3VtYpTvGdAgmAoGu37MUiikkcoMgNT4Pawr8+z18 091A== 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 ch5si5461829edb.190.2020.11.12.19.23.57; Thu, 12 Nov 2020 19:24:19 -0800 (PST) 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 S1726277AbgKMDTt (ORCPT + 99 others); Thu, 12 Nov 2020 22:19:49 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7187 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726007AbgKMDTt (ORCPT ); Thu, 12 Nov 2020 22:19:49 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CXNxN1FRtz15Vv4; Fri, 13 Nov 2020 11:19:36 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Fri, 13 Nov 2020 11:19:39 +0800 From: Hanjun Guo To: Felix Kuehling CC: , , Hanjun Guo Subject: [PATCH v3 2/2] drm/amdkfd: Put ACPI table after using it Date: Fri, 13 Nov 2020 11:11:14 +0800 Message-ID: <1605237074-58920-2-git-send-email-guohanjun@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1605237074-58920-1-git-send-email-guohanjun@huawei.com> References: <1605237074-58920-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 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 c23e571..0dc8de0 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c @@ -774,6 +774,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; @@ -798,14 +799,17 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size) } pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL); - if (!pcrat_image) - return -ENOMEM; + if (!pcrat_image) { + rc = -ENOMEM; + goto out; + } memcpy(pcrat_image, crat_table, crat_table->length); *crat_image = pcrat_image; *size = crat_table->length; - - return 0; +out: + acpi_put_table(crat_table); + return rc; } /* Memory required to create Virtual CRAT. @@ -988,6 +992,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