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 7962E37EFE3 for ; Mon, 24 Aug 2026 17:54:13 +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=1787594054; cv=none; b=BNt+6eJHXxuFCOo35irkRIGE8siefPCHcII7EtGbwftBx04UWYHvNbW7Uar3BrFsd6MPNRWy2AAch1LcfH6V+H3m67Q34Tw92fwpFlcFCLEhVfNFfX3rnLr7H2RcVQqGKdzzmk8cvneVeJfcUo1bdgs0JByKUZZgoq2lEE3Fkbg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787594054; c=relaxed/simple; bh=F73B1BuJjmqo+1Mc0dH4UfVYigcW7B+LDiGk11jKaVk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hVm9p5E81WC0V+KPawRN9SOm3KHzGCvXF1IuJfSKs24MlDkV84Uz1bWd9rt/Nlzc2Z/05HZO4XdDw2tQftobEE9gugbEgbIJtDxKrgFupaqOyi6w5OxfiG6A3MaKMaNcZ2Eu6/TkMyvMSznaPeCmkFcctHNzJvbwdy0x+UxCXMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=axxnnmVQ; 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="axxnnmVQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C69871F000E9; Mon, 24 Aug 2026 17:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787594053; bh=ri+SzAfwgqIPsOLjp7gc+8mlEz0L/2cv2KM8Su7FUxA=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=axxnnmVQmAqcuslqPEo4V/HD9KG7tFf+cn3HvIey74UZM2eButzAk5Cs91Of04JgL KKUQ5xnxiOhvw3gWS7CLevizF6N2tdelE67JgA+UC94TUxm9k/uaixejVijfCb/7gR Zxu0bDxM1lseze1x2UcHgWFjFq7QY42rC/60Bdt8d5v86K6An18jwTrKq1iTbfj0D1 YXt+CUnOTfyCWGmbNylyAdfxP5Ie4GO58Lxvln+eWN0V7RivFSesrsB9C2DnJsoKC0 TukaoDM3AC4T8VGZZ+0gERlyg0G+eIkAVzSHfP6FGyvmUW51JlX/mSP3+8cCPMTYPP CoBFRGO3w7wwg== Message-ID: Date: Mon, 24 Aug 2026 12:54:11 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/amd_node: Fix PCI device reference counting in amd_smn_init() Content-Language: en-US To: Yazen Ghannam , x86@kernel.org Cc: linux-kernel@vger.kernel.org References: <20260824175003.335196-1-yazen.ghannam@amd.com> From: Mario Limonciello In-Reply-To: <20260824175003.335196-1-yazen.ghannam@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 8/24/26 12:50, 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 Reviewed-by: Mario Limonciello (AMD) > --- > 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