Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp863943rwd; Wed, 7 Jun 2023 07:54:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AsHupAgLoDN5FO8A16vnZAz1B4cMWOJAb+er2uBO6JFvW/4o+UM2UAYGvoilRxKRYYNRt X-Received: by 2002:a05:6a21:339a:b0:f0:50c4:4c43 with SMTP id yy26-20020a056a21339a00b000f050c44c43mr3316067pzb.5.1686149670110; Wed, 07 Jun 2023 07:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686149670; cv=none; d=google.com; s=arc-20160816; b=GUtam+rclKkSOSlotWCatNRFeBV/UkbVCp3xcV1Rhoio9Yccz9tmCRWj87siF4v6OB SixVGyfe6lv0Y5j3ve2SzcsJKu+xJiuKtepeOC8GP9h4svpkkRiAsLS3lrCI5vYtiEVI vPBtK1Nwp5gXL9xoApwfhav8tJw8E2uCDsgTCv9nTv80/04/n3z/kMkuV0ia3PnU9Wzn 11tGdnu2Z4cSnyltJ+DyFzY9LpvAXh5hFCjFNzBowVA/v2FG4Vk+FPA/Ui7sgdFeGqso LVIW/W8goK+T6f348n3lo3LOdNX3IhAv+JhHkC+VGdtb8w2grv/H8e4XZ8mcWTo7Vh7J 25AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LqYHTiTmt+6bkokPZgd7QYzZ8bhU2nwFDSU1EUKZZAw=; b=lp5umDQ7NyBOseI7z2vLylRVWgTagfr0Klaj45ZwN/sJmcRNHoUGZ3yuNE4frpqvv6 KuGgUDbd5h/dRn1XVuTljl5uPofJNw4JSYT4V/9vco3W0Tmkt6jZKOTPgG5fuCvzPEJ1 EDoZImPwFwmYpXWecE1RMbf12Cg47OPMSdDDM3aakxpnUIImoDpZuCBEeBg4DZMrC8wn XN3hQlS64xtdZDHJ2IWEJHe9a4z0dGCIhmcBhJZOqAZTzeYdHmaMK3Fn0hQ6Ao2lUfUx rhJxgjpJXGGxkPU743YsCmeEe+9nw9W9zYYxDSlUdJWCbEEf+I7Azj1CaGLNq7o88yLc DpQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=jb0R5N3w; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v5-20020aa799c5000000b0065d39e113cfsi4431388pfi.228.2023.06.07.07.54.17; Wed, 07 Jun 2023 07:54:30 -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=@ziepe.ca header.s=google header.b=jb0R5N3w; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240440AbjFGOWs (ORCPT + 99 others); Wed, 7 Jun 2023 10:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239767AbjFGOWr (ORCPT ); Wed, 7 Jun 2023 10:22:47 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 593DC1BCA for ; Wed, 7 Jun 2023 07:22:46 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-64d57cd373fso481262b3a.1 for ; Wed, 07 Jun 2023 07:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1686147766; x=1688739766; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=LqYHTiTmt+6bkokPZgd7QYzZ8bhU2nwFDSU1EUKZZAw=; b=jb0R5N3wy/ARkSOwsfs8wIpDDWZOCLPYl9Oylyey830OFdJtm87SmtHdCKAq/LQiAH rwmGPpis5/8ni1oCofH2ZuRgryc+pv4WcEqnuqYTAg3Gp8+4YPPM7cn0aSLFPow92ive zO6VbcvKOoYyTZyZyvaLI4/CuMqtSKrcrWSPWpSYujBhp5yu5UqKDeJAKqSNFOEFJK4d vAbCGYfDWHdiMs69lm2mYNNPLeMTouW43dNA61gH5G1HAiY6XAUx11v4rL7/3Dh1hjgY ZUkfV0zNnYQwii3B6T8cgOvuTKx7NCF7GOwF4oGn+x5QXORzo99WY8cgEBI4GqS2tzKK pINA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686147766; x=1688739766; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LqYHTiTmt+6bkokPZgd7QYzZ8bhU2nwFDSU1EUKZZAw=; b=Ef7JVPYoYrvxAeQ3kWw5MPM1VF2SThzAfxXwoR2J7OdnHeH8tEilx5naJiv8KEXSmu 5E6ESmhkifdSQyzV5zFsJyTiVqyhx053aBtqVh8EQ3O+q1hztqAREbKlRw3WUViSTNNd UXbn4/wIhaY3gZTZDnBmVjvWsTLqioYE1O9kjQTJiEPOEnsqH0xzegTqbCd5ypuCRNop 10Wr4pWyb1AlQj0su/taOLaJ+YNd37DoY9Q48JEtgHh5p9On1Kau+aQcMJEM/Q5X8wrD 1IlIv65lIwPbzbZrt9FwQKKhfkgYjzvd5i38GqoO+VV1wvhkF1iW2cZVpmRAxGZ8HUCs d4zw== X-Gm-Message-State: AC+VfDzy7Al41AhxY1q6qTMr+fY9mTjVQek1mt34UsnWibZQCP/CCF0u FQpLsgO2q6IfuTb9/RWaqCsduNsLN8j9LCFXxv8= X-Received: by 2002:a17:903:244d:b0:1b0:56cf:b8c0 with SMTP id l13-20020a170903244d00b001b056cfb8c0mr7246032pls.13.1686147765817; Wed, 07 Jun 2023 07:22:45 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id f23-20020a170902ab9700b001b1a2bf5274sm10497227plr.22.2023.06.07.07.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 07:22:45 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1q6u3e-003A3r-Kv; Wed, 07 Jun 2023 11:22:42 -0300 Date: Wed, 7 Jun 2023 11:22:42 -0300 From: Jason Gunthorpe To: Su Hui Cc: Joerg Roedel , Suravee Suthikulpanit , Will Deacon , Robin Murphy , kevin.tian@intel.com, vasant.hegde@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu/amd: Fix possible memory leak of 'domain' Message-ID: References: <20230606070742.139575-1-suhui@nfschina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230606070742.139575-1-suhui@nfschina.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 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 Reviewed-by: Jason Gunthorpe Thanks, Jason