* [PATCH v3 0/3] ata: Do not release the host resources twice on probe() failure
@ 2026-09-10 12:19 Niklas Cassel
2026-09-10 12:19 ` [PATCH v3 1/3] ata: ahci_st: Assert the power down reset in the probe() error path Niklas Cassel
0 siblings, 1 reply; 2+ messages in thread
From: Niklas Cassel @ 2026-09-10 12:19 UTC (permalink / raw)
To: Patrice Chotard, Damien Le Moal, Niklas Cassel, Hans de Goede,
Philipp Zabel, Tejun Heo, Alexandre Torgue, Lee Jones,
Brian Norris, Jeff Garzik
Cc: linux-arm-kernel, 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v3 1/3] ata: ahci_st: Assert the power down reset in the probe() error path
2026-09-10 12:19 [PATCH v3 0/3] ata: Do not release the host resources twice on probe() failure Niklas Cassel
@ 2026-09-10 12:19 ` Niklas Cassel
0 siblings, 0 replies; 2+ messages in thread
From: Niklas Cassel @ 2026-09-10 12:19 UTC (permalink / raw)
To: Patrice Chotard, Damien Le Moal, Niklas Cassel, Philipp Zabel,
Lee Jones, Alexandre Torgue, Tejun Heo
Cc: Brian Norris, stable, linux-arm-kernel, linux-ide
st_ahci_probe_resets() deasserts the "pwr-dwn" reset, but the probe()
error path of st_ahci_probe() only releases the host resources, so the
SATA IP is left powered up when probe() fails after
st_ahci_probe_resets() has succeeded, e.g. when
ahci_platform_enable_resources() fails.
The reset is asserted by st_ahci_host_stop(), however ->host_stop() is
only called through the ata_host_stop() devres action registered by
ata_host_start(), so it does not cover any failure happening before the
host has been started.
Factor the assert out into st_ahci_assert_pwrdwn() and call it from both
probe() error paths. The "pwr-dwn" reset control is an exclusive one, so
asserting it once more from st_ahci_host_stop() is harmless.
No functional change intended for ->host_stop() and st_ahci_suspend().
Fixes: 76884cb2f7da ("ahci: st: Add support for ST's SATA IP")
Cc: stable@vger.kernel.org
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/ata/ahci_st.c | 51 +++++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 21 deletions(-)
diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c
index 4336c8a6e208..39ebedf93344 100644
--- a/drivers/ata/ahci_st.c
+++ b/drivers/ata/ahci_st.c
@@ -83,18 +83,27 @@ static int st_ahci_deassert_resets(struct ahci_host_priv *hpriv,
return 0;
}
-static void st_ahci_host_stop(struct ata_host *host)
+static int st_ahci_assert_pwrdwn(struct ahci_host_priv *hpriv,
+ struct device *dev)
{
- struct ahci_host_priv *hpriv = host->private_data;
struct st_ahci_drv_data *drv_data = hpriv->plat_data;
- struct device *dev = host->dev;
int err;
- if (drv_data->pwr) {
- err = reset_control_assert(drv_data->pwr);
- if (err)
- dev_err(dev, "unable to pwrdwn\n");
- }
+ if (!drv_data->pwr)
+ return 0;
+
+ err = reset_control_assert(drv_data->pwr);
+ if (err)
+ dev_err(dev, "unable to pwrdwn\n");
+
+ return err;
+}
+
+static void st_ahci_host_stop(struct ata_host *host)
+{
+ struct ahci_host_priv *hpriv = host->private_data;
+
+ st_ahci_assert_pwrdwn(hpriv, host->dev);
ahci_platform_disable_resources(hpriv);
}
@@ -162,38 +171,38 @@ static int st_ahci_probe(struct platform_device *pdev)
err = ahci_platform_enable_resources(hpriv);
if (err)
- return err;
+ goto assert_pwrdwn;
st_ahci_configure_oob(hpriv->mmio);
err = ahci_platform_init_host(pdev, hpriv, &st_ahci_port_info,
&ahci_platform_sht);
- if (err) {
- ahci_platform_disable_resources(hpriv);
- return err;
- }
+ if (err)
+ goto disable_resources;
return 0;
+
+disable_resources:
+ ahci_platform_disable_resources(hpriv);
+assert_pwrdwn:
+ st_ahci_assert_pwrdwn(hpriv, &pdev->dev);
+
+ return err;
}
static int st_ahci_suspend(struct device *dev)
{
struct ata_host *host = dev_get_drvdata(dev);
struct ahci_host_priv *hpriv = host->private_data;
- struct st_ahci_drv_data *drv_data = hpriv->plat_data;
int err;
err = ahci_platform_suspend_host(dev);
if (err)
return err;
- if (drv_data->pwr) {
- err = reset_control_assert(drv_data->pwr);
- if (err) {
- dev_err(dev, "unable to pwrdwn");
- return err;
- }
- }
+ err = st_ahci_assert_pwrdwn(hpriv, dev);
+ if (err)
+ return err;
ahci_platform_disable_resources(hpriv);
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-10 12:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 12:19 [PATCH v3 0/3] ata: Do not release the host resources twice on probe() failure Niklas Cassel
2026-09-10 12:19 ` [PATCH v3 1/3] ata: ahci_st: Assert the power down reset in the probe() error path Niklas Cassel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox