From: sashiko-bot@kernel.org
To: "Unsung Lee" <unsung0317@gmail.com>, linux-cxl@vger.kernel.org
Subject: Re: [PATCH] cxl/port: Do not queue a memdev detach when the memdev unbinds itself
Date: Sun, 22 Nov 2026 12:39:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-227929@kernel.org> (raw)
In-Reply-To: <20261122122014.2194208-1-unsung0317@gmail.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] cxl/port: dangling pointer in cxl_port_add() on
device_add() failure [1]
--
commit 0b760e3be76b85ac20765da3eb83e58f481f44d5
Author: Unsung Lee <unsung0317@gmail.com>
cxl/port: Do not queue a memdev detach when the memdev unbinds itself
This commit marks a memdev as unbinding during delete_endpoint() so that
schedule_detach() does not queue a redundant detach work item when a
memdev without an ->attach callback is being unbound directly.
> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index fffcb9954dde5..4960a288a1166 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -1514,9 +1514,12 @@ static void delete_endpoint(void *data)
>
> scoped_guard(device, host) {
> if (host->driver && !endpoint->dead) {
> + /* @cxlmd is going away, see schedule_detach() */
> + WRITE_ONCE(cxlmd->unbinding, true);
> devm_release_action(host, cxl_unlink_parent_dport, endpoint);
> devm_release_action(host, cxl_unlink_uport, endpoint);
> devm_release_action(host, unregister_port, endpoint);
> + WRITE_ONCE(cxlmd->unbinding, false);
> }
> cxlmd->endpoint = NULL;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but in the paired setup path
cxl_port_add() [1], does a device_add() failure leave
cxlmd->endpoint dangling?
drivers/cxl/core/port.c:cxl_port_add() {
struct device *dev __free(put_device) = &port->dev;
...
if (is_cxl_memdev(port->uport_dev)) {
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
...
cxlmd->endpoint = port;
}
...
rc = device_add(dev);
if (rc)
return rc;
}
When device_add() fails, the __free(put_device) cleanup drops the final
reference and frees port without clearing cxlmd->endpoint, leaving a
dangling pointer that can cause a use-after-free on later teardown.
[1] https://sashiko.dev/#/bug/linux-66ab7dca-4e52-440e-82d0-9a0b35e9f79c
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122122014.2194208-1-unsung0317@gmail.com?part=1
prev parent reply other threads:[~2026-11-22 12:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 12:20 [PATCH] cxl/port: Do not queue a memdev detach when the memdev unbinds itself Unsung Lee
2026-11-22 12:39 ` 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-227929@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=unsung0317@gmail.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