All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yazen Ghannam <yazen.ghannam@amd.com>
To: <x86@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <mario.limonciello@amd.com>,
	Yazen Ghannam <yazen.ghannam@amd.com>
Subject: [PATCH] x86/amd_node: Fix PCI device reference counting in amd_smn_init()
Date: Mon, 24 Aug 2026 12:50:03 -0500	[thread overview]
Message-ID: <20260824175003.335196-1-yazen.ghannam@amd.com> (raw)

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 <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260806160159.230453-1-jason.andryuk%40amd.com
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
 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");
 
@@ -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


             reply	other threads:[~2026-08-24 17:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 17:50 Yazen Ghannam [this message]
2026-08-24 17:54 ` [PATCH] x86/amd_node: Fix PCI device reference counting in amd_smn_init() Mario Limonciello
2026-08-25  3:59 ` Serge Hallyn (AMD)
2026-08-25 13:52   ` Yazen Ghannam
2026-08-25 14:35     ` Yazen Ghannam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260824175003.335196-1-yazen.ghannam@amd.com \
    --to=yazen.ghannam@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.