[PATCH v3 0/3] ata: Do not release the host resources twice on probe() failure
From: Niklas Cassel <cassel@kernel.org>
Date: 2026-09-10 12:19:20
Also in:
linux-ide
ata_host_start() registers ata_host_stop() as a devres action as soon as
it has succeeded:
if (have_stop) {
start_dr = devres_alloc(ata_host_stop, 0, GFP_KERNEL);
...
if (start_dr)
devres_add(host->dev, start_dr);
host->flags |= ATA_HOST_STARTED;
From that point on, releasing the host resources is owned by devres: when
probe() fails, the driver core calls devres_release_all(), which calls
ata_host_stop(), which calls ->port_stop() and ->host_stop().
ata_host_activate() and ahci_host_activate_multi_irqs() can however fail
after ata_host_start() has succeeded - devm_kasprintf(),
devm_request_irq() (a shared IRQ conflict) and ata_host_register()
(scsi_add_host(), ata_tport_add()) can all fail - and they return the
error with the devres action still registered. Since the caller cannot
tell whether ata_host_start() succeeded, and since it has to release the
resources for the failures happening before that, all the ahci-platform
drivers release the host resources in their probe() error path, e.g.
ahci_probe() calls ahci_platform_disable_resources() while
ahci_host_stop() does the same through devres.
The clocks, regulators, resets and PHYs of the host are therefore
released twice, which gives refcount underflow warnings from the clk,
regulator and phy cores and, for shared resources, can disable resources
which are still in use by other devices.
Patch 2 adds ata_host_undo_start(), which stops the ports and drops the
devres action without calling ->host_stop(), and calls it from both
activation helpers when they fail, so that "on failure, the caller
releases what it acquired" holds for all of them. sata_qstor and sata_fsl
are the only drivers which implement ->host_stop() while having no error
handling at all for the activate host call, so they get some.
Patch 1 has to come first: ahci_st is the only ahci-platform driver whose
->host_stop() does more than its probe() error path, as it also asserts
the "pwr-dwn" reset. Without patch 1, patch 2 would silently stop that
reset from being asserted when activating the host fails.
Patch 3 is an unrelated kdoc fix that I noticed while documenting the
above.
Changes since v2:
- Do not take the host teardown back in ata_pci_sff_activate_host(), and
drop the sata_nv change which went with it. None of its callers
releases the host resources itself: ata_piix, pata_rdc and
ata_pci_init_one() all rely on ->host_stop() being called through
devres, ata_pci_init_one() by releasing the devres group of the host.
- Document who releases the host resources on failure in the kdoc of
ata_host_activate(), ata_host_register(), ata_pci_sff_activate_host(),
ahci_host_activate() and ahci_platform_init_host().
- New patch 1, so that patch 2 does not stop ahci_st from asserting its
"pwr-dwn" reset on probe() failure.
- New patch 3.
Niklas Cassel (3):
ata: ahci_st: Assert the power down reset in the probe() error path
ata: libata: Do not leave ata_host_stop() registered when activation
fails
ata: libata-core: Fix the ata_host_register() kdoc
drivers/ata/ahci_st.c | 51 ++++++++++++---------
drivers/ata/libahci.c | 17 ++++++-
drivers/ata/libahci_platform.c | 4 ++
drivers/ata/libata-core.c | 81 ++++++++++++++++++++++++++++++----
drivers/ata/libata-sff.c | 5 +++
drivers/ata/sata_fsl.c | 8 +++-
drivers/ata/sata_qstor.c | 8 +++-
include/linux/libata.h | 1 +
8 files changed, 139 insertions(+), 36 deletions(-)
--
2.55.0