Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1005151lqd; Thu, 25 Apr 2024 03:18:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKK5FVGyWxZFivvQwaS/5ccov3c8VAPdQpDRGeiazB2TcZ4wI9k/EzyR7bVhvfezscpxY1q8SrOqBMJkqGu9hcTKVHjsZjTVtH7t2g6Q== X-Google-Smtp-Source: AGHT+IFMgQHG1bGCHKFAy7y1/SZSB6obyxiqgkMNo676f+JEJo4AzI1ZWIU6KU0pHbHx6UH4N1wr X-Received: by 2002:a50:a693:0:b0:56e:23db:3e87 with SMTP id e19-20020a50a693000000b0056e23db3e87mr3503892edc.11.1714040332385; Thu, 25 Apr 2024 03:18:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714040332; cv=pass; d=google.com; s=arc-20160816; b=bSHFqGkcRtBh6pMqcGWa7GHtJVyVNOZKOiHoQ8iIy7s59NF5amRl2W4p/54/8DePgI +U601zLoiMNiUZaZAwQAzqTEy7nlUfFtsp2yskUpt6afUnhYv+EfayuC/lSJTp3bhpEO UmdZt+HV2oqwl3YCdiF8K1FhIGEaOesv+T4IbjwjG80plNKIHBosbQyxAxJpy16XkSce mXOZfBz9xE19N2GSzA/cON7u8GfpKxIgT4vl3iVQJ4z50OdPqnkykpWLP+QacwBQW8Dd KNdUQsLKT0QBiyC+iuhqq/gZhwdcY5a9YzlGiSuqN/LNoxdiIUQI16ZNo6VwBi2B5w3T S2/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=QcCGmMZke9wNUqDSX//NGSJSaxDB+PepcH2WxN5WEqo=; fh=l73Y1neKT7m4vtS4QpSWf+LfOyqMQQGYZR3LPR+X/z8=; b=V+OJMilMz/2J2jZ34Fu0YZBTY+YzgGZWj5q1hWijndTBcgAOhpE/Q/xOnHJ8gijLuJ AA0uhi1uWCPlhJ53xbx9XVdy5U4CQaolXUzmFPqRnMson6LuW4n6e8yWJI4VusFDRMXV lYDzGhXbWzCANavXRI3JJ/Zm9NQtninnl9tlPPdzNhOR4/zRnVseCTTmTK4UAlBqMAsQ VoMOIfCWTY6rO5lBsmL7KmNS5D0582KNnL7BI1th22P2CuSlI2COZHp8kqdEU032uyCh QU1ILXv1iQizmqjTAhnXLUcq5Yfce5Hf98Dl6H6SrRDkxEojk8Tp5lLCUfgwpf3XTQGm FBrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=gXoWfZaL; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-158378-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158378-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g5-20020a056402180500b00568386368c5si9382278edy.690.2024.04.25.03.18.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 03:18:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158378-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=gXoWfZaL; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-158378-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158378-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B69081F22628 for ; Thu, 25 Apr 2024 10:18:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9BAE126F0D; Thu, 25 Apr 2024 10:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="gXoWfZaL" Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C74938614D for ; Thu, 25 Apr 2024 10:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040301; cv=none; b=BfGQs9HLNvZ4uwa9iURDsdf23GFS8LMbusApFLpLYHufvbrKJjtgvOzEdeLgkBfd5ZbJeYhAz5Sgd5rXbuZt5I+/0v/wIqQmHQF3PJagtpLaBbR98EBXU2Dg4Z5Tnrdad19Tt9CldwSMSNS5xVmDdmzGLhvcbNUHkLZL0UgKJWc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040301; c=relaxed/simple; bh=qpx9spVeO8CkWFjQ72oQekACDvn3i/PHgcVhhu25UTc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oFbQInRBwOKIpNJ0JOsSJgNBaz6/ZNl/owvkFkbXQDSGJdSbe/OGO2SxDLduCcqfXRBNRjzt0NtFJpk24iHtJR9QsEhHk6Qn53UfwdlE+h8lSWsa0xq7AmlWdbjm6mhdVrXORkdzzhknKGHHa+anxXYGKtJqZWSQYDAXlSp06H8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=gXoWfZaL; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1714040297; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=QcCGmMZke9wNUqDSX//NGSJSaxDB+PepcH2WxN5WEqo=; b=gXoWfZaLXRG3rQuUUH2JZfgR0/KI3yErqZFobq5FlEzG/5yJc+IgspoH7ffIyY5iCX/tdxEl4+e5wItSbJhZ80PV3g55HsZxYXUhZ2sn5FFX6IOiinl/UATbu3YNA9tN1YxJmaF7tvaCejq1ssD5rrfmVadx/YgMnQxuLAZLMlo= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R461e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067110;MF=llfl@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0W5F8.U6_1714040295; Received: from localhost(mailfrom:llfl@linux.alibaba.com fp:SMTPD_---0W5F8.U6_1714040295) by smtp.aliyun-inc.com; Thu, 25 Apr 2024 18:18:16 +0800 From: "Kun(llfl)" To: Joerg Roedel , Vasant Hegde Cc: Suravee Suthikulpanit , Will Deacon , Robin Murphy , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/1] iommu/amd: Fix memory leak in alloc_pci_segment() Date: Thu, 25 Apr 2024 18:17:20 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Fix the memory leak issue that occurs when resource allocation fails in alloc_pci_segment(). The dev_table, alias_table, and rlookup_table were introduced individually in three commits. But they all fail to release allocated resources when other allocations fail. Fixes: 04230c119930 ("iommu/amd: Introduce per PCI segment device table") Fixes: 99fc4ac3d297 ("iommu/amd: Introduce per PCI segment alias_table"), Fixes: eda797a27795 ("iommu/amd: Introduce per PCI segment rlookup table"). Reported-by: Xuchun Shang Signed-off-by: Kun(llfl) --- drivers/iommu/amd/init.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index ac6754a85f35..4ce567f39473 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1642,13 +1642,22 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list); if (alloc_dev_table(pci_seg)) - return NULL; + goto alloc_dev_fail; if (alloc_alias_table(pci_seg)) - return NULL; + goto alloc_alias_fail; if (alloc_rlookup_table(pci_seg)) - return NULL; + goto alloc_rlookup_fail; return pci_seg; + +alloc_rlookup_fail: + free_rlookup_table(pci_seg); +alloc_alias_fail: + free_alias_table(pci_seg); +alloc_dev_fail: + free_dev_table(pci_seg); + kfree(pci_seg); + return NULL; } static struct amd_iommu_pci_seg *__init get_pci_segment(u16 id, -- 2.43.0