Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v1 3/7] ACPI: bus: Drop initialized flag from struct acpi_device_flags
Date: Mon, 31 Aug 2026 21:03:16 +0000	[thread overview]
Message-ID: <20260831210316.857181F000E9@smtp.kernel.org> (raw)
In-Reply-To: <3782570.R56niFO833@rafael.j.wysocki>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removing the `initialized` flag causes the device enumeration check to remain true after a failed hot-remove eject, leading to a double-detach and a NULL pointer dereference (e.g., in `acpi_pci_root_remove()`) upon subsequent status checks.
--

commit 8f4c1e701ec6dd8150885a28ad18d087926defd7
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

ACPI: bus: Drop initialized flag from struct acpi_device_flags

After previous changes, the ACPI device object "initialized" flag is
not particularly useful. It is set almost all the time and it is
only checked along with the "visited" flag, but checking the latter
is sufficient. Drop it accordingly.

> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 5aa3ecb000e14..019a43e3b5d7f 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -281,7 +281,6 @@ static int acpi_scan_check_and_detach(struct acpi_device *adev, void *p)
>  	 * that.
>  	 */
>  	acpi_device_set_power(adev, ACPI_STATE_D3_COLD);
> -	adev->flags.initialized = false;
>  
>  	/* For eject this is deferred to acpi_bus_post_eject() */
>  	if (!(flags & ACPI_SCAN_CHECK_FLAG_EJECT)) {

[Severity: High]
Could removing this state barrier cause a double-detach and a NULL pointer
dereference if a hot-remove eject fails?

When a hot-remove eject operation is initiated (ACPI_SCAN_CHECK_FLAG_EJECT),
acpi_scan_check_and_detach() executes handler->detach(adev).

For a PCI root device, acpi_pci_root_remove() frees the acpi_pci_root
structure and sets device->driver_data = NULL. At this stage, adev->handler
and adev->flags.visited are intentionally left uncleared because they are
deferred to acpi_bus_post_eject().

If the firmware eject (_EJ0) fails, acpi_scan_hot_remove() aborts and
acpi_bus_post_eject() is skipped. This leaves the device in the tree with
adev->handler attached and visited = 1.

Before this patch, adev->flags.initialized = false was unconditionally set
during the eject phase, so a subsequent status check would evaluate
acpi_device_enumerated() to false and safely abort.

By removing the initialized flag, the status check relies solely on visited.
This bypasses the early return and executes handler->detach(adev) a second
time.

Handlers like acpi_pci_root_remove() do not check if acpi_driver_data() is
NULL on a second pass, and will crash when dereferencing root->bus:

drivers/acpi/pci_root.c:acpi_pci_root_remove() {
    ...
    struct acpi_pci_root *root = acpi_driver_data(device);
    
    pci_lock_rescan_remove();
    pci_stop_root_bus(root->bus);
    ...
}

[ ... ]

> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index b0d9057ccb8ab..596fbd748e88d 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -654,7 +653,7 @@ void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
>  
>  static inline bool acpi_device_enumerated(struct acpi_device *adev)
>  {
> -	return adev && adev->flags.initialized && adev->flags.visited;
> +	return adev && adev->flags.visited;
>  }

[Severity: High]
Does this change bypass the protection that initialized provided during failed
hot-remove operations as described above?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/3435655.aeNJFYEL58@rafael.j.wysocki?part=3

  reply	other threads:[~2026-08-31 21:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 16:20 [PATCH v1 0/7] ACPI: scan: Address power management initialization and PCI devices handling Rafael J. Wysocki
2026-08-31 16:24 ` [PATCH v1 1/7] ACPI: scan: Stop calling acpi_bus_init_power() early Rafael J. Wysocki
2026-08-31 20:14   ` sashiko-bot
2026-09-01 17:31     ` Rafael J. Wysocki (Intel)
2026-09-01  8:27   ` Andy Shevchenko
2026-08-31 16:25 ` [PATCH v1 2/7] ACPI: PM: Introduce acpi_device_init_power() Rafael J. Wysocki
2026-08-31 20:25   ` sashiko-bot
2026-09-01  8:29   ` Andy Shevchenko
2026-09-01 16:38     ` Rafael J. Wysocki (Intel)
2026-08-31 17:59 ` [PATCH v1 3/7] ACPI: bus: Drop initialized flag from struct acpi_device_flags Rafael J. Wysocki
2026-08-31 21:03   ` sashiko-bot [this message]
2026-08-31 17:59 ` [PATCH v1 4/7] ACPI: scan: Combine two conditionals in acpi_bus_attach() Rafael J. Wysocki
2026-08-31 21:05   ` sashiko-bot
2026-09-01  8:40   ` Andy Shevchenko
2026-09-01 19:11     ` Rafael J. Wysocki (Intel)
2026-08-31 17:59 ` [PATCH v1 5/7] ACPI: scan: Add ACPI device "enumerated" marker Rafael J. Wysocki
2026-08-31 21:14   ` sashiko-bot
2026-08-31 17:59 ` [PATCH v1 6/7] ACPI: scan: Adjust and rename acpi_bus_attach() Rafael J. Wysocki
2026-08-31 21:17   ` sashiko-bot
2026-08-31 17:59 ` [PATCH v1 7/7] ACPI: scan: Take PCI device enumeration into account directly Rafael J. Wysocki
2026-08-31 21:23   ` sashiko-bot
2026-09-01  8:44   ` Andy Shevchenko
2026-09-01 19:14     ` Rafael J. Wysocki (Intel)
2026-09-02 12:42 ` [PATCH v1 0/7] ACPI: scan: Address power management initialization and PCI devices handling Peixin Xie

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=20260831210316.857181F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rafael@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