From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 48EC6383C66 for ; Tue, 25 Aug 2026 03:59:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787630372; cv=none; b=W4390txNGzdHodUl4qqQu4DbiPdwP5A8NXt5S20/GYmal8dkJC1+ohM3bWF+o2PoGNHhTubkcS+NmlJ7/1n3yw9OEWilaH3DWAyOGiljECooyfRrQQ/J4JlorNQNqnXLVI8f5Lgx5/HrpcqvJCsG5RyEpS2A2sht/o+VuNZEfPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787630372; c=relaxed/simple; bh=GY7A/tU+gdkCg8Q8g/DXeUo9+oQdk0HTNmB9r2IAV1w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eAN3+mOW6bfMOe8f8sSa/7nSBLns4+59WDv6KUizFQQOcpLlbzIvqoADRY8Fl3JoVc/Xf+UebmviPb6QmLVsuJDtbuuKQIgYSZV+Dwhh/w/baSai5P5KsEwWGyux52pAXdaVYjIOzNtpNGTCbciNn5UcTKioJa1sdStJW30yvDc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GtVeG3Zq; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GtVeG3Zq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47DBA1F000E9; Tue, 25 Aug 2026 03:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787630370; bh=0NRchZdmxkqMYZ9ryuFnCLRluID8UiAFDgrssbPnDJA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=GtVeG3ZqlyFajOJlCKMmO3xyBft7MD+2aRGOIdbMenohzZU3he2iyZr8jLD/g23vP cNT4jnHAQvTm11jRyW4R3mPCUNvK0Yj8QiCB6SdeD9P5CQNR7/Bx8I6X+cGRkSPWDQ nB9uZFOQtkaKdk+AS0t1NeSKHoEF1KgO0wrtfKIzhLoy7tfZfRIjKpS9RsrZ/Nv+li tO4Me/c51Ns+OWFCQuilXboWKAQrqQQagDXlSSOGu9ROFNh9CTySCfMI89JH4hJflS JA0aT66fpnf2xHyJkIMEr/jABqKgptPJg2VvHSLqTTm+FqJj5LMObAuHDNh1KhKUwt XlLJ45v7JRM+A== Date: Mon, 24 Aug 2026 22:59:28 -0500 From: "Serge Hallyn (AMD)" To: Yazen Ghannam Cc: x86@kernel.org, linux-kernel@vger.kernel.org, mario.limonciello@amd.com Subject: Re: [PATCH] x86/amd_node: Fix PCI device reference counting in amd_smn_init() Message-ID: References: <20260824175003.335196-1-yazen.ghannam@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260824175003.335196-1-yazen.ghannam@amd.com> On Mon, Aug 24, 2026 at 12:50:03PM -0500, Yazen Ghannam wrote: > The local "root" pointer is a temporary variable used during the device > search. Therefore, refcount related to the search iterators should be > cleaned up after the search is complete. > > Use the __free() cleanup macro to ensure the refcount is decremented > when the temporary pointer goes out of scope. > > Additionally, increment the refcount when caching a root pointer. This > ensures the in-use refcount is separate from the temporary search > refcounting. > > Fixes: 0a4b61d9c2e4 ("x86/amd_node: Fix AMD root device caching") > Reported-by: Sashiko > Closes: https://sashiko.dev/#/patchset/20260806160159.230453-1-jason.andryuk%40amd.com > Assisted-by: Claude-Code:claude-opus-5 > Signed-off-by: Yazen Ghannam > --- > arch/x86/kernel/amd_node.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kernel/amd_node.c b/arch/x86/kernel/amd_node.c > index 0be01725a2a4..312adf73313b 100644 > --- a/arch/x86/kernel/amd_node.c > +++ b/arch/x86/kernel/amd_node.c > @@ -247,7 +247,7 @@ __setup("amd_smn_debugfs_enable", amd_smn_enable_dfs); > static int __init amd_smn_init(void) > { > u16 count, num_roots, roots_per_node, node, num_nodes; > - struct pci_dev *root; > + struct pci_dev *root __free(pci_dev_put) = NULL; > > if (!cpu_feature_enabled(X86_FEATURE_ZEN)) > return 0; > @@ -258,7 +258,6 @@ static int __init amd_smn_init(void) > return 0; > > num_roots = 0; > - root = NULL; > while ((root = get_next_root(root))) { > pci_dbg(root, "Reserving PCI config space\n"); > Will this leak the ref taken on the last get_next_root(root) in the first loop? You might need a pci_dev_put(root) before the root = NULL above the second loop. Or I could be wrong. > @@ -297,7 +296,7 @@ static int __init amd_smn_init(void) > continue; > > pci_dbg(root, "is root for AMD node %u\n", node); > - amd_roots[node++] = root; > + amd_roots[node++] = pci_dev_get(root); > } > > if (enable_dfs) { > > base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f > -- > 2.43.0 >