Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chunfeng Yun" <chunfeng.yun@mediatek.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v4 06/14] thunderbolt: Consolidate domain and NHI teardown into tb_nhi_remove()
Date: Sat, 05 Dec 2026 08:50:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-251306@kernel.org> (raw)
In-Reply-To: <20261205083342.4009278-7-chunfeng.yun@mediatek.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] thunderbolt: split pm_runtime_allow() and undocumented
  tb_nhi_remove() PM
--

commit 836a017990ff5baedafc35035fd228fa66590e97
Author: Chunfeng Yun <chunfeng.yun@mediatek.com>

thunderbolt: Consolidate domain and NHI teardown into tb_nhi_remove()

This commit moves the common domain and NHI teardown steps from
nhi_pci_do_remove() into a new tb_nhi_remove() helper in nhi.c and makes
nhi_shutdown() static.

> diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
> index 41a6ec03c4e74..cf83ce54fca40 100644
> --- a/drivers/thunderbolt/nhi.c
> +++ b/drivers/thunderbolt/nhi.c
[ ... ]
> @@ -1404,6 +1404,35 @@ int tb_nhi_probe(struct tb_nhi *nhi)
>  	return res;
>  }
>  
> +/**
> + * tb_nhi_remove() - Remove and release NHI instance and its domain
> + * @nhi: Pointer to the NHI structure
> + * @reset: Whether to force a host router reset (e.g. on shutdown/reboot)
> + *
> + * Common teardown sequence across all bus types. Stops and unregisters
> + * the domain, waits for domain release, and shuts down the NHI hardware.
> + */
> +void tb_nhi_remove(struct tb_nhi *nhi, bool reset)
> +{
[ ... ]
> +	pm_runtime_get_sync(dev);
> +	pm_runtime_dont_use_autosuspend(dev);
> +
> +	tb_domain_remove(tb);
> +	wait_for_completion(&nhi->domain_released);
> +	nhi_shutdown(nhi);
> +}
[ ... ]
> diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c
> index 96280942e7083..9e48946c1d6bd 100644
> --- a/drivers/thunderbolt/pci.c
> +++ b/drivers/thunderbolt/pci.c
> @@ -568,21 +568,11 @@ static void nhi_pci_do_remove(struct pci_dev *pdev, bool reset)
>  	struct tb *tb = pci_get_drvdata(pdev);
>  	struct tb_nhi *nhi = tb->nhi;
>  
> -	/*
> -	 * On system shutdown/reboot force a host router reset so the
> -	 * connection manager asserts DPR on connected Thunderbolt 3 devices
> -	 * before the router tree is removed (see tb_stop()).
> -	 */
> -	if (reset)
> -		nhi->host_reset = true;
> -
> -	pm_runtime_get_sync(&pdev->dev);
> -	pm_runtime_dont_use_autosuspend(&pdev->dev);
> +	/* Restore PCI device to forbid state */
>  	pm_runtime_forbid(&pdev->dev);
>  
> -	tb_domain_remove(tb);
> -	wait_for_completion(&nhi->domain_released);
> -	nhi_shutdown(nhi);
> +	tb_nhi_remove(nhi, reset);
> +
>  	nhi_pci_release_msi(nhi_to_pci(nhi));
>  }

[Severity: Medium]
Should pm_runtime_allow() also move into nhi_pci_probe() now that
pm_runtime_forbid() stays in nhi_pci_do_remove()?

PCI devices start forbidden in pci_pm_init(), while non-PCI devices start
allowed.  Leaving pm_runtime_allow(dev) in tb_nhi_probe() silently
overrides userspace power/control=on on platform NHI devices (commit
"thunderbolt: Add platform NHI driver"), allowing runtime suspend.

Also, tb_nhi_remove() takes an unbalanced pm_runtime_get_sync(dev), so
callers must keep runtime PM enabled on entry and drop the reference
afterwards.  That contract is undocumented in kernel-doc and contradicts
the commit message saying backends only handle PM before tb_nhi_remove().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205083342.4009278-1-chunfeng.yun@mediatek.com?part=6

  reply	other threads:[~2026-12-05  8:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  8:33 [PATCH v4 00/14] thunderbolt: Add platform NHI driver and modularize PCIe NHI Chunfeng Yun
2026-12-05  8:33 ` [PATCH v4 01/14] thunderbolt: Fix error handling and unwind paths in nhi_probe() Chunfeng Yun
2026-12-05  8:50   ` sashiko-bot
2026-12-05  8:33 ` [PATCH v4 02/14] thunderbolt: Prefix NHI core symbols with tb_ and tb_ring_ Chunfeng Yun
2026-12-05  8:33 ` [PATCH v4 03/14] thunderbolt: Internalize non-MSI-X interrupt request and work in NHI core Chunfeng Yun
2026-12-05  8:51   ` sashiko-bot
2026-12-05  8:33 ` [PATCH v4 04/14] thunderbolt: Encapsulate router device type checks in switch.c Chunfeng Yun
2026-12-05  8:41   ` sashiko-bot
2026-12-05  8:33 ` [PATCH v4 05/14] thunderbolt: Move rpm_complete bus walk to domain.c Chunfeng Yun
2026-12-05  8:50   ` sashiko-bot
2026-12-05  8:33 ` [PATCH v4 06/14] thunderbolt: Consolidate domain and NHI teardown into tb_nhi_remove() Chunfeng Yun
2026-12-05  8:50   ` sashiko-bot [this message]
2026-12-05  8:33 ` [PATCH v4 07/14] thunderbolt: Move ICM mailbox functions to icm.c Chunfeng Yun
2026-12-05  8:33 ` [PATCH v4 08/14] thunderbolt: Decouple ICM probe from NHI core via .select_cm hook Chunfeng Yun
2026-12-05  8:33 ` [PATCH v4 09/14] thunderbolt: Make PCIe NHI support opt-in Chunfeng Yun
2026-12-05  8:58   ` sashiko-bot
2026-12-05  8:33 ` [PATCH v4 10/14] thunderbolt: Make nhi->ops optional Chunfeng Yun
2026-12-05  8:33 ` [PATCH v4 11/14] thunderbolt: Add platform NHI driver Chunfeng Yun
2026-12-05  8:56   ` sashiko-bot
2026-12-05  8:33 ` [PATCH v4 12/14] thunderbolt: Increase the lane adapter link-up timeout value Chunfeng Yun
2026-12-05  8:33 ` [PATCH v4 13/14] thunderbolt: Decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP Chunfeng Yun
2026-12-05  8:56   ` sashiko-bot
2026-12-05  8:33 ` [PATCH v4 14/14] thunderbolt: Drop WARN_ON() in tb_disconnect_pci() Chunfeng Yun
2026-12-05  8:55   ` sashiko-bot
2026-12-05  8:58 ` [PATCH v4 00/14] thunderbolt: Add platform NHI driver and modularize PCIe NHI sashiko-bot

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-251306@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chunfeng.yun@mediatek.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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