Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lin Wang" <wanglin@open-hieco.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v8 7/7] x86/hygon: Add Family 0x18 SMN access
Date: Thu, 22 Oct 2026 07:52:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-181145@kernel.org> (raw)
In-Reply-To: <20261022074218.667049-8-wanglin@open-hieco.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] x86/hygon: unreferenced reserved_roots allocation in smn_setup()
--

commit 9932a3551c6b7f805f9889c0454dbe666f4f46a0
Author: Lin Wang <wanglin@open-hieco.net>

x86/hygon: Add Family 0x18 SMN access

This commit adds system management network access support for Hygon
Family 0x18 processors by mapping data fabric nodes to per-socket root
complexes and providing serialized read and write helpers.

> diff --git a/arch/x86/kernel/hygon_node.c b/arch/x86/kernel/hygon_node.c
> index 03c723aab97e3..7b0a18cd7027a 100644
> --- a/arch/x86/kernel/hygon_node.c
> +++ b/arch/x86/kernel/hygon_node.c
[ ... ]
> @@ -629,6 +631,229 @@ static int __maybe_unused hygon_pci_dev_to_df_node(struct pci_dev *pdev)
[ ... ]
> +static struct pci_dev	**smn_roots;
> +static struct pci_dev	**smn_reserved_roots;
> +static u16		smn_num_nodes;
> +static DEFINE_MUTEX(smn_mutex);
[ ... ]
> +static int __init smn_setup(void)
> +{
> +	u16 num_roots, roots_per_socket, node, num_nodes, num_sockets, reserved;
> +	struct pci_dev **reserved_roots, **roots;
> +	struct pci_dev *root = NULL;
> +	u8 socket_id;
> +	int ret;
[ ... ]
> +	roots = kzalloc_objs(*roots, num_nodes);
> +	if (!roots)
> +		return -ENOMEM;
> +
> +	reserved_roots = kzalloc_objs(*reserved_roots, num_roots);
> +	if (!reserved_roots) {
> +		kfree(roots);
> +		return -ENOMEM;
> +	}
[ ... ]
> +	for (node = 0; node < num_nodes; node++) {
> +		socket_id = df_cache.nodes[node].socket_id;
> +
> +		if (socket_id >= num_sockets) {
> +			ret = -ENODEV;
> +			goto err_release;
> +		}
> +
> +		roots[node] = reserved_roots[socket_id * roots_per_socket];
> +
> +		pci_dbg(roots[node],
> +			"is root for Hygon node %u (socket %u)\n",
> +			node, socket_id);
> +	}
> +
> +	smn_reserved_roots = reserved_roots;
> +	smn_num_nodes = num_nodes;
> +	smn_roots = roots;
> +	return 0;

[Severity: Medium]
Does df_node_init() -> smn_setup() in arch/x86/kernel/hygon_node.c leak the
reserved_roots array once initialization completes?

In smn_setup(), reserved_roots is allocated with kzalloc_objs() to track
reserved root devices for error rollback via release_reserved_roots() and
to populate roots[node]. At the end of smn_setup(), reserved_roots is
assigned to the file-scope static variable smn_reserved_roots, which is
never read anywhere in arch/x86/kernel/hygon_node.c.

Because smn_reserved_roots is a write-only static variable with internal
linkage, the compiler optimizes away both the variable and the store to it.
Once smn_setup() returns, no reference to the reserved_roots allocation
remains in memory (as smn_roots only holds pointers to the individual
pci_dev objects), which leaves the array leaked and triggers a kmemleak
report.

Since the device references from pci_dev_get() and the config space
reservations from pci_request_config_region_exclusive() are held by the
pci_dev objects themselves, could smn_reserved_roots be removed and
reserved_roots freed with kfree(reserved_roots) before smn_setup() returns
0?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261022074218.667049-1-wanglin@open-hieco.net?part=7

      reply	other threads:[~2026-10-22  7:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22  7:42 [PATCH v8 0/7] x86/hygon: Add Family 0x18 DF node enumeration and SMN access Lin Wang
2026-10-22  7:42 ` [PATCH v8 1/7] x86/hygon: Add Family 0x18 DF node enumeration Lin Wang
2026-10-22  7:49   ` sashiko-bot
2026-10-24 15:15   ` Yazen Ghannam
2026-10-22  7:42 ` [PATCH v8 2/7] x86/hygon: Map CPU NodeIds to DF nodes Lin Wang
2026-10-22  7:56   ` sashiko-bot
2026-10-22  7:42 ` [PATCH v8 3/7] EDAC/amd64: Stop matching Hygon CPUs Lin Wang
2026-10-22  7:45   ` sashiko-bot
2026-10-22  7:42 ` [PATCH v8 4/7] RAS/AMD/ATL: Match AMD CPUs only Lin Wang
2026-10-22  7:46   ` sashiko-bot
2026-10-22  7:42 ` [PATCH v8 5/7] x86/amd_nb: Restrict the northbridge framework to AMD CPUs Lin Wang
2026-10-22  7:48   ` sashiko-bot
2026-10-22  7:42 ` [PATCH v8 6/7] x86/amd_node: Restrict SMN setup " Lin Wang
2026-10-22  7:49   ` sashiko-bot
2026-10-22  7:42 ` [PATCH v8 7/7] x86/hygon: Add Family 0x18 SMN access Lin Wang
2026-10-22  7:52   ` sashiko-bot [this message]

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=sashiko-outbox-181145@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wanglin@open-hieco.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox