Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp863096rwd; Wed, 7 Jun 2023 07:53:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jTCG2nw42Qm6h8dwpMbZc1DOcG9isD/2MzAAPIOclG+k9L5QcIQXUrJDRhSwVOBOhEHmL X-Received: by 2002:a17:90b:4d83:b0:258:de21:f237 with SMTP id oj3-20020a17090b4d8300b00258de21f237mr2446850pjb.9.1686149625065; Wed, 07 Jun 2023 07:53:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686149625; cv=pass; d=google.com; s=arc-20160816; b=OYrdoITutcH9TW6T4owjGOEVZs36RL5vElMDNqG/Em/0tLecm17yqGp0+3R+gPSasj 4gZFsuAjuo5qf+k7/t141Cy7dzPqACrqXDWEzGq8HQ0t9vjglA1KIF+HAVvAMTZmtvdP PTWBqZcX5Z2moQdInce9jzB3MCCckig2gG22lFkgm9fhF01blmQA9Fdr4dcmZYP483G6 pk5pSmGplvESrhCKc/YjLUMNcOJ1M6541/IjzQQctrHa8KgnELudmbEP8t6fPVAxqt2V NaycZ0PFHtfKvxhSoGmfoQ+6TTbMS4TVGtpvyNPu1UCCdiT8arIPuUFYINeq2EhncUws iTtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=klUT5iWVOkTuLfutogB3eY62d/IukKFoFSrhJIShIC4=; b=I3OBOLN0eAAhnZ7oFRwTUF9fktPW6Ot3c4QPyzOR8yIe01kmlyLz+WltHsmLeqRb1Y 3I8NFf15BvxmFzP/UAXVOQIoo7KYAC7NqpWgU0t3HhUCkK4nUn1oflnL2whz34BFx79A MNUcDBw2//o2Mau0xRvjcqEDpQnWRh+U8wVdIw1bFb7veDjSPS0bIODhxj54V8Ocw9Y4 /PYtdy2zRPkmtxRWCEjDerwFTNpoEFAPwwecEHI2B5SCmUfxP4Jr2zsqc3ef4DYUWISQ m2v23Rq5ssKb0HfyTz/F8gkbzl1pdPpLAcrnFSCPWEeXQ288U050vBTLMeriQclqNXUX QQuw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="4EjE8Oo/"; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w10-20020a17090a8a0a00b002509d96227esi1169618pjn.173.2023.06.07.07.53.32; Wed, 07 Jun 2023 07:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="4EjE8Oo/"; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235147AbjFGO1O (ORCPT + 99 others); Wed, 7 Jun 2023 10:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239120AbjFGO1J (ORCPT ); Wed, 7 Jun 2023 10:27:09 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2054.outbound.protection.outlook.com [40.107.93.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CB3BE43 for ; Wed, 7 Jun 2023 07:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AkMc963CvkdEozqcw7x70AZYkkQtk0Yqrpa5tQsEEE3gtVIlL0JeLZHN9Q+0bqrd/KJeYffpt6/xNE3BdIDNOHo7JICMhe8QY69+ogReRjMKBMIYWyOivmmFWIAIssk878kVqA3XjMgejLQQwCYmMzsbbMOMRwK5+1pHzlmGCNl7LX+wRByNM1zwB1vhDR2D5EKXo5kMz0h0qoXzXC/rqlqsaAE3MCsf7X3DCc4xEkF89lFkRd93M2yIFD1LquSZFtkv06SiLuegBl+4DuZcJk4rv45rdjk8NlKpDzJrtFb1wHkWboU9xgz0BZNPpgmJIn++t2sYmsI997SHufO24w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=klUT5iWVOkTuLfutogB3eY62d/IukKFoFSrhJIShIC4=; b=WiWsCtAsPtHFTKdfbQRcQ3Apmy3NoA5PJp3Mi8DqusSXyG3AJ1R6sU6kVNJ+eyBpJRPkRh+/ZiMHODJK9tz1sUTT4AGk9xSsMjYVpPEAA/Ea8uPI7TQG1qWZu1sdZbdcDq9eYwVycd6hDO2pD0Ay5kMUyFkJoY2ZRyqCaScMx4Xr29UuAlQ8kN/+nV9A4N1pI+Vz7PBd6JFswFTeMVip1A3qlxWYf+zcLe64K85Wg6J0hGoc4l2FyaksvekOfNuVajJzphuN+/CXvkTjOvuDRRnF5RlycCCM+emSlhyDfvCJ9NZtlWdqGr6C/eFpArHvEo7nnsZUKyCZ38iGflj/qQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=klUT5iWVOkTuLfutogB3eY62d/IukKFoFSrhJIShIC4=; b=4EjE8Oo/4QbDrF6B5ETSRM3eDDH83h8dSS42lKizz7zwIb/sf8kwJbUw/y0IyBtrRcwRL9A1xFzfnM/XFG2qVdlZsfHF4KMK4dhnEchgAcmfs1nf/xkbUq7+k1T5Gbi23UFWIWABMkCwgKVszXARI7TMj0gOhH5PeQRqt91FFu4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DS7PR12MB6048.namprd12.prod.outlook.com (2603:10b6:8:9f::5) by BL1PR12MB5318.namprd12.prod.outlook.com (2603:10b6:208:31d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Wed, 7 Jun 2023 14:27:03 +0000 Received: from DS7PR12MB6048.namprd12.prod.outlook.com ([fe80::7cbf:236a:55b:2c99]) by DS7PR12MB6048.namprd12.prod.outlook.com ([fe80::7cbf:236a:55b:2c99%4]) with mapi id 15.20.6455.030; Wed, 7 Jun 2023 14:27:03 +0000 Message-ID: <95c1cc02-cd5d-c454-7c29-e4c42a6bd54c@amd.com> Date: Wed, 7 Jun 2023 19:56:51 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH] iommu/amd: Fix possible memory leak of 'domain' Content-Language: en-US To: Jason Gunthorpe , Su Hui Cc: Joerg Roedel , Suravee Suthikulpanit , Will Deacon , Robin Murphy , kevin.tian@intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20230606070742.139575-1-suhui@nfschina.com> From: Vasant Hegde In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MA0PR01CA0073.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:ad::12) To DS7PR12MB6048.namprd12.prod.outlook.com (2603:10b6:8:9f::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB6048:EE_|BL1PR12MB5318:EE_ X-MS-Office365-Filtering-Correlation-Id: 84f1317f-d4aa-4138-116e-08db6763432f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3wHjr3GWIEQjL4SYewfSOrFGtEL9KVE/zBGoMd5Yqkpr1lIs2ghwyQQ/W5TAqaVExNYxWGKAKdAX09fUWzZPLjD+/hiyAyBWXI1fqnHq+0YkETlzdQOM48s7/ubR8x/PUbhx/C7y6uDd8a0bYKVO7nkWNWTvn8sZuHJTcr1dV60Hae41YKmQyxcys0AjItEeZFCpCi558YONROdNvCltJ1on37g9xMQZg+3v0xcuhyrA23eqZQw714yD5gjTb3ZnqxUrL0vM6Nxh6oF+6tv96USXs5y36Jey/af+QSxkSiF/pY2Dby+ODUffQkNPeMvZtXq53Cbtvd6A3TQ2m+mIBzddlMa+UeyMy18f0gxKKEii+Z0eX0fDx9akbz6i8qZZ+nOp2vg09bJ5b2ei8tJ3/Xm5LQ1JJCuZ4457DGTF+0Y1LPgSf7tDkoI6CQdke8Me2AnUS3xt7PD3vIB8Bdqhhd3eXt1FOv+nXZym+sfDQa+ZLIRMBlmMiILwiCyc755YTcsuCWBWA4pt5ivpEMfdphYRcM/cbSpArvgQwLpdI8lodu3MjCMy7TjRcSJqvNuLztwOFogXs+cwKgQP+QmVN5HhX0fEU8qi9swbX/LyFsgiJmJpax9y511EPm8/xdGWRE6hN64cfMsuUuFtLkB7B50B1gNAkm4abocPpd7LGwcXqXM5wy6/j8qI/OUmqON/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB6048.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(136003)(39860400002)(366004)(396003)(451199021)(8676002)(4326008)(66556008)(66476007)(8936002)(66946007)(316002)(5660300002)(31686004)(41300700001)(54906003)(110136005)(44832011)(2906002)(478600001)(26005)(38100700002)(31696002)(6512007)(86362001)(6506007)(53546011)(186003)(36756003)(6486002)(2616005)(83380400001)(6666004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?b1BzeDU2YndUbkR0ZlY2R1hLRVBYamFZZkVjd0pQbXM3alNZVCtLSzdEbGY4?= =?utf-8?B?em5pM3U3UTROb2kySFJmMDlhays2MGRDL3FSM1BhekVUWFBuajVYUWhNeXQr?= =?utf-8?B?bXNRNGhwRHh1V1JzbDRBT05pU2hnbzlJWUdvczhJZWhPWmFWNUxFTFV5TFVC?= =?utf-8?B?eXpHbEZmVi80NXBLRVFIMTlIam1FbG9VWm1wWm9yemxGbURnMnRReDNUNDBV?= =?utf-8?B?TDVZSE10bmZ4d0tOb2ZDcW5JRm0yaU9QUTNJRC9lemtNam9rL0t6MVRSTzVx?= =?utf-8?B?bjJrSnN3SVFrS3hCRTAxa1d2Yjk3eDdKYUlKM1dnNTlPM1VKVDZmQzdjWitS?= =?utf-8?B?RzhKL2pnbXAxNFM0T09lS04yc2lUVkFDcVFySXNZejZTdDlXN3VZNnp4Q1l3?= =?utf-8?B?Sk0venBmcFpuSmtPMC9DdjQzUkJYNW1QVFAvR0FWZzFuNWszNndoR0lWTzQx?= =?utf-8?B?TjI0WmJXQzIxaDEyeXBkMTMySDdBNzRtOWhiVXRPcUxoMVZuWXlrM1VpQWNo?= =?utf-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GwyZjZV?= =?utf-8?B?NzNFSXdKZ2liL1dIOHh6TEhNUDF1bUFueVQ3bCtTN2dZSzA5SUlUSHZQVzdU?= =?utf-8?B?V09DU1p0L0p0L2R5UjVycFgrOHNHNC9manAxcWJiM3BVS1FqZkhHVlgyWkp6?= =?utf-8?B?MWhUWTk3NEZQM0Y4S3I2ejF0clZNUURzUGZpZGhCQ2tCR0ZEeDNsRUFvZTk2?= =?utf-8?B?RWpkWS85WFNFQzd2K3ZHeWV4NnNEYzZUVnd3Rk0vMXQ1aVZ1MURPQTB0dXFN?= =?utf-8?B?bWRBUTh4TCtEQ1Q0UnZsbFFSd1BSUXZReTF0engxZXYzT0oxVFBSY1grL2Z5?= =?utf-8?B?amZVOUcrUnlMVVY3UWJBcGlwUjRXQW5FOFl1Y1dtSlpGWm5TUDhJWWJsOVFm?= =?utf-8?B?UEdHNC9idGVIb3ljaFNNWXRhbjY5amp1SVozK25PMW5pQkhXVHIwSWh4aHhY?= =?utf-8?B?SjA0MWNkVXZoV3ZzM1pseU5ybjVIU0J6QWF5TEhWZkJKN1JBemxnVmVUUFBy?= =?utf-8?B?MU8wSEgxZ1haY2l5alQxNGJhR1RaeFlweXR2Sm1vTzNYSWt1U2NBM3FTK296?= =?utf-8?B?QndYNWVjRlZFcXhhRlAzdVJmSU02UGZlN0dBeCtMTnAwSkFiVjV6VUJkNzZH?= =?utf-8?B?eU1VMlh4SEVpaEhrUTdwOEVSTFcvbEJPVzh2SFREd3czVXBiNTBzaG1NeVFP?= =?utf-8?Q?6LNKCn4/QNgpQzoQZOKaIf7j7?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84f1317f-d4aa-4138-116e-08db6763432f X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB6048.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2023 14:27:03.5186 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4qXKvytFNkd/RJ0x6WwabkcfPDky3v3oetcG9s+lazgOTKf7R4ts+d7sVT1qWGcWNIN/j7aBhLVoa37EUlWdZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5318 X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jason, On 6/7/2023 7:52 PM, Jason Gunthorpe wrote: > On Tue, Jun 06, 2023 at 03:07:42PM +0800, Su Hui wrote: >> free memory of domain before return NULL. >> >> Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks") >> Signed-off-by: Su Hui >> --- >> drivers/iommu/amd/iommu.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c >> index dc1ec6849775..f08e65629c74 100644 >> --- a/drivers/iommu/amd/iommu.c >> +++ b/drivers/iommu/amd/iommu.c >> @@ -2094,7 +2094,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) >> } else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) { >> pgtable = amd_iommu_pgtable; >> } else { >> - return NULL; >> + goto out_err; >> } > > It might be nicer to order to allocation after the type checks, it is > more consistent with the other drivers > > This is fine too Right. We are working on cleaning up/re-arranging this code path. Hopefully I will have patches soon. -Vasant