Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sherry Sun (OSS)" <sherry.sun@oss.nxp.com>
Cc: imx@lists.linux.dev, linux-pci@vger.kernel.org,
	devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	Frank.Li@kernel.org
Subject: Re: [PATCH V6 3/4] Bluetooth: btnxpuart: Add M.2 Bluetooth device support using pwrseq
Date: Mon, 13 Jul 2026 02:42:50 +0000	[thread overview]
Message-ID: <20260713024251.36B3D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260713023435.235765-4-sherry.sun@oss.nxp.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Brittle logic causing probe failure on valid hardware topologies.

Pre-existing issues:
- [High] Race condition exposing device before initializing synchronization primitives.
- [High] Use-after-free and locking a destroyed mutex during device teardown.
--

--- Patch [3]: [PATCH V6 3/4] Bluetooth: btnxpuart: Add M.2 Bluetooth device support using pwrseq ---
commit 885432311fa71ac754d16037ae3e761e8192452c
Author: Sherry Sun <sherry.sun@nxp.com>

Bluetooth: btnxpuart: Add M.2 Bluetooth device support using pwrseq

Power supply to the M.2 Bluetooth device attached to the host using M.2
connector is controlled using the uart pwrseq device. This commit adds
support for getting the pwrseq device if the OF graph link is present.

> diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c
> --- a/drivers/bluetooth/btnxpuart.c
> +++ b/drivers/bluetooth/btnxpuart.c

[ ... ]

> @@ -1872,11 +1875,26 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
>  		return err;
>  	}
>  
> +	if (of_graph_is_present(dev_of_node(&serdev->ctrl->dev))) {
> +		struct pwrseq_desc *pwrseq;
> +
> +		pwrseq = pwrseq_get(&serdev->ctrl->dev, "uart");
> +		if (IS_ERR(pwrseq))
> +			return dev_err_probe(&serdev->dev, PTR_ERR(pwrseq),
> +					     "failed to get pwrseq\n");

[Severity: High]
If the parent UART node has an OF graph for other purposes, like audio
routing or multiplexing, will this unconditionally fail the driver probe?

When of_graph_is_present() returns true, pwrseq_get() might return an
error like -ENOENT if there is no power sequencer configured for the
uart target.

Could this logic be made less brittle to support valid hardware topologies
where the UART has an OF graph but no power sequencer?

> +
> +		nxpdev->pwrseq = pwrseq;
> +		err = pwrseq_power_on(pwrseq);
> +		if (err)
> +			goto err_pwrseq_put;
> +	}

[ ... ]

> @@ -1907,13 +1925,16 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
>  	if (bacmp(&ba, BDADDR_ANY))
>  		hci_set_quirk(hdev, HCI_QUIRK_USE_BDADDR_PROPERTY);
>  
> -	if (hci_register_dev(hdev) < 0) {
> +	err = hci_register_dev(hdev);
> +	if (err < 0) {
>  		dev_err(&serdev->dev, "Can't register HCI device\n");
>  		goto probe_fail;
>  	}
>  
> -	if (ps_setup(hdev))
> +	if (ps_setup(hdev)) {
> +		err = -ENODEV;
>  		goto probe_fail_unregister;
> +	}

[Severity: High]
This is a pre-existing issue, but does calling hci_register_dev() before
ps_setup() create a race condition during initialization?

When hci_register_dev() is called, it schedules the power_on work
asynchronously, which opens the UART port via btnxpuart_open().

Once the UART is open, incoming data triggers the receive path:

btnxpuart_receive_buf()
  ps_wakeup()

ps_wakeup() attempts to lock psdata->ps_lock and schedule psdata->work.

If ps_setup() has not yet completed its initialization of these structures,
could this result in operating on an uninitialized mutex or workqueue?

>  
>  	hci_devcd_register(hdev, nxp_coredump, nxp_coredump_hdr,

[ ... ]

> @@ -1952,6 +1976,8 @@ static void nxp_serdev_remove(struct serdev_device *serdev)
>  		}
>  	}
>  
>  	ps_cleanup(nxpdev);
>  	hci_unregister_dev(hdev);

[Severity: High]
This is a pre-existing issue, but does calling ps_cleanup() before
hci_unregister_dev() cause a use-after-free or a lock on a destroyed mutex?

ps_cleanup() destroys psdata->ps_lock and cancels psdata->work.

However, hci_unregister_dev() shuts down the device. During this shutdown
process, the UART can still receive data or send commands.

If data is received or sent, the paths btnxpuart_receive_buf() to
ps_wakeup() or nxp_enqueue() will attempt to acquire the destroyed
psdata->ps_lock.

Should hci_unregister_dev() be called before cleaning up the
synchronization primitives?

>  	reset_control_assert(nxpdev->pdn);
> +	if (nxpdev->pwrseq)
> +		pwrseq_put(nxpdev->pwrseq);
>  	hci_free_dev(hdev);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260713023435.235765-1-sherry.sun@oss.nxp.com?part=3

  reply	other threads:[~2026-07-13  2:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13  2:34 [PATCH V6 0/4] Add PCIe M.2 Key E connector support for NXP i.MX boards Sherry Sun (OSS)
2026-07-13  2:34 ` [PATCH V6 1/4] PCI: imx6: Move pci_pwrctrl_create_devices() to imx_pcie_probe() Sherry Sun (OSS)
2026-07-13  2:47   ` sashiko-bot
2026-07-13  2:34 ` [PATCH V6 2/4] PCI: imx6: Add skip_pwrctrl_off flag support Sherry Sun (OSS)
2026-07-13  2:45   ` sashiko-bot
2026-07-13  2:34 ` [PATCH V6 3/4] Bluetooth: btnxpuart: Add M.2 Bluetooth device support using pwrseq Sherry Sun (OSS)
2026-07-13  2:42   ` sashiko-bot [this message]
2026-07-13  4:03     ` Sherry Sun
2026-07-13  4:56   ` Manivannan Sadhasivam
2026-07-13  2:34 ` [PATCH V6 4/4] arm64: dts: imx95-19x19-evk: Describe the PCIe M.2 Key E connector Sherry Sun (OSS)
2026-07-13  2:42   ` sashiko-bot
2026-07-13  5:07 ` (subset) [PATCH V6 0/4] Add PCIe M.2 Key E connector support for NXP i.MX boards Manivannan Sadhasivam

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=20260713024251.36B3D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=linux-pci@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sherry.sun@oss.nxp.com \
    /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