From nobody Fri Dec 19 07:20:08 2025 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) (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 3C7B3763F8 for ; Sat, 31 Aug 2024 05:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.206.16.166 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725081868; cv=none; b=Z8KgmX0+vXkgizFwNbTLqPM9BG0KTMaWxw4MoxOWuPmzmhBut4f5reh8ukAJPQlx0Di/3N9OYLipb91fQAeWKuvdMQto55zun+hQ/D0pLvVsEQlqoJXNVjikoXy46lVfgf4P/WWFFwX+2SRpV7Q69Fs7ZymYbo/spwXa+2ufm5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725081868; c=relaxed/simple; bh=Qrydd6FpfGREKFpUumfU+PND9ypJPQ0rvGA5gim0Y0I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=EVO6yAzdQQvQ4uokWwkyctibgh/vTEZ61abOG13Xfa9m8xb7oYE9lbyekJb/sT7HL+NZ4SK4J1pjaQp8e7XLyrTuuSOjCIyAvDr25co9RsjVL2Itwxq0nX8P6ckWCFmfcKCRSkZO27I+w7gZz8XEEZXSlf1pKpVE2xwDFyPqKJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=lS6+8Lqe; arc=none smtp.client-ip=54.206.16.166 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="lS6+8Lqe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1725081795; bh=BeFS78svjvX4dgZ/pXmTXrW3I/8Ubt/o8uwqmQay4rc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=lS6+8LqeCYg27XDxF6TuwCvzN6M0aLM/fliy5tWtRFWZa268/Xxk0s6vg9uKjveLA CGvctqtcpp0hNI3VUkz2Q6msqowr961ol/zxRbA3g5Anp5vk011EDaX9a5WRA7ro/p ZuvpwkJLiaAtcXaoGUcFIVsqDakXw0nXNy3nQixs= X-QQ-mid: bizesmtp85t1725081789tfeka6ky X-QQ-Originating-IP: E3dMKFpfvXJ0xiShuJTZplZjy33NIhkzA8HM6/RTArs= Received: from localhost.localdomain ( [111.172.4.23]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 31 Aug 2024 13:23:07 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 2311621511106180187 From: Wentao Guan To: henhuacai@kernel.org, kernel@xen0n.name, loongarch@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Wentao Guan , Wangyuli Subject: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root Date: Sat, 31 Aug 2024 13:21:57 +0800 Message-Id: <20240831052157.13532-1-guanwentao@uniontech.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz5a-0 Content-Type: text/plain; charset="utf-8" Add kfree(root_ops) in this case to avoid memleak root_ops, leaks when pci_find_bus() !=3D 0. Also delay assign root_ops when used for making code read clean. Found by code review Signed-off-by: Wangyuli Signed-off-by: Wentao Guan --- arch/loongarch/pci/acpi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/loongarch/pci/acpi.c b/arch/loongarch/pci/acpi.c index 3eb61b8cd5e3..7f3539f5fa23 100644 --- a/arch/loongarch/pci/acpi.c +++ b/arch/loongarch/pci/acpi.c @@ -219,17 +219,18 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_ro= ot *root) return NULL; } =20 - root_ops->release_info =3D acpi_release_root_info; - root_ops->prepare_resources =3D acpi_prepare_root_resources; - root_ops->pci_ops =3D (struct pci_ops *)&info->cfg->ops->pci_ops; - bus =3D pci_find_bus(domain, busnum); if (bus) { memcpy(bus->sysdata, info->cfg, sizeof(struct pci_config_window)); kfree(info); + kfree(root_ops); } else { struct pci_bus *child; =20 + root_ops->release_info =3D acpi_release_root_info; + root_ops->prepare_resources =3D acpi_prepare_root_resources; + root_ops->pci_ops =3D (struct pci_ops *)&info->cfg->ops->pci_ops; + bus =3D acpi_pci_root_create(root, root_ops, &info->common, info->cfg); if (!bus) { --=20 2.20.1