FAILED: patch "[PATCH] ata: libata: Do not leave ata_host_stop() registered when activation fails" failed to apply to 6.1-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x d2f977008cbbae195df678ee1e70e5802f9bd0b8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From d2f977008cbbae195df678ee1e70e5802f9bd0b8 Mon Sep 17 00:00:00 2001
From: Niklas Cassel <[email protected]>
Date: Tue, 15 Sep 2026 10:41:31 +0200
Subject: [PATCH] ata: libata: Do not leave ata_host_stop() registered when
activation fails
ata_host_start() registers ata_host_stop() as a devres action as soon as it has succeeded, which hands the release of the host resources over to
devres: ->port_stop() and ->host_stop() are then called by the driver core when probe() fails.
ata_host_activate() and ahci_host_activate_multi_irqs() can both fail after ata_host_start() has succeeded, e.g. if devm_request_irq() or ata_host_register() fails, and they return the error with the devres action still registered. A driver which releases the host resources in its probe() error path therefore releases them twice: once itself and once through ->host_stop().
All ahci-platform drivers are in that situation, e.g. ahci_probe() calls ahci_platform_disable_resources() while ahci_host_stop() does the same through devres. This 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.
Add ata_host_undo_start(), which stops the ports and drops the devres action without calling ->host_stop(), and call it from both activation helpers when they fail. Releasing the host resources on failure is then always left to the caller, which is what all callers having a probe() error path already assume.
This changes the semantics for the drivers which implement ->host_stop() while also completely lacking error handling for the activate host call. Add activate host error handling for sata_qstor and sata_fsl. For sata_fsl this also means that hcr_base and host_priv are now released when activating the host fails, which ->host_stop() did not do when ata_host_start() itself failed.
Note that ata_pci_sff_activate_host() is deliberately left as is: none of its callers releases the host resources in its probe() error path, they all rely on ->host_stop() being called by devres, including ata_pci_init_one(), which releases the devres group of the host itself.
--- drivers/ata/libahci.c | 2 + drivers/ata/libahci_platform.c | 4 ++ drivers/ata/libata-core.c | 75 +++++++++++++++++++++++++++++++--- drivers/ata/libata-sff.c | 5 +++ drivers/ata/sata_fsl.c | 6 ++- drivers/ata/sata_qstor.c | 8 +++- include/linux/libata.h | 1 + 7 files changed, 91 insertions(+), 10 deletions(-)
drivers/ata/libahci.c +2 -0
@@ -2750,6 +2750,8 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host, host->ports[i]); } +ata_host_undo_start (host); +return rc; }
drivers/ata/libahci_platform.c +4 -0
@@ -689,6 +689,10 @@ EXPORT_SYMBOL_GPL(ahci_platform_get_resources);* ahci-platform host, note any necessary resources (ie clks, phys, etc.) * must be initialized / enabled before calling this. * +* On failure, ->host_stop() is not called, so the caller has to release the +* resources it enabled (clocks, regulators, resets, PHYs) in its probe() +* error path. +* * RETURNS: * 0 on success otherwise a negative error code */
drivers/ata/libata-core.c +69 -6
114 lines not on this page · raw message
drivers/ata/libata-sff.c +5 -0
@@ -2267,6 +2267,11 @@ EXPORT_SYMBOL_GPL(ata_pci_sff_prepare_host);* hosts. This separate helper is necessary because SFF hosts * use two separate interrupts in legacy mode. * +* Note that, unlike ata_host_activate(), the devres action registered +* by ata_host_start() is kept on failure, i.e. ->host_stop() is called +* by the driver core when probe() fails. All callers of this function +* rely on that, none of them releases the host resources itself. +* * LOCKING: * Inherited from calling layer (may sleep). *
drivers/ata/sata_fsl.c +4 -2
@@ -1490,8 +1490,10 @@ static int sata_fsl_probe(struct platform_device *ofdev)* device discovery process, invoking our port_start() handler & * error_handler() to execute a dummy Softreset EH session */ -ata_host_activate (host, irq, sata_fsl_interrupt,SATA_FSL_IRQ_FLAG , - &sata_fsl_sht); + retval =ata_host_activate (host, irq, sata_fsl_interrupt, +SATA_FSL_IRQ_FLAG , &sata_fsl_sht); +if (retval) + goto error_exit_with_cleanup; host_priv->intr_coalescing.show = fsl_sata_intr_coalescing_show; host_priv->intr_coalescing.store = fsl_sata_intr_coalescing_store;
drivers/ata/sata_qstor.c +6 -2
@@ -584,8 +584,12 @@ static int qs_ata_init_one(struct pci_dev *pdev,qs_host_init (host, board_idx);pci_set_master (pdev); -return ata_host_activate (host, pdev->irq, qs_intr,IRQF_SHARED , - &qs_ata_sht); + rc =ata_host_activate (host, pdev->irq, qs_intr,IRQF_SHARED , + &qs_ata_sht); +if (rc) +qs_host_stop (host); + +return rc; }module_pci_driver (qs_ata_pci_driver);
include/linux/libata.h +1 -0
@@ -1147,6 +1147,7 @@ extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,extern void ata_host_get (struct ata_host *host);extern void ata_host_put (struct ata_host *host);extern int ata_host_start (struct ata_host *host); +void ata_host_undo_start (struct ata_host *host);extern int ata_host_register (struct ata_host *host,const struct scsi_host_template *sht); extern int ata_host_activate(struct ata_host *host, int irq,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 ata: libata: Do not leave ata_host_stop() registered when activation fails
From: Niklas Cassel <[email protected]>
[ Upstream commit d2f977008cbbae195df678ee1e70e5802f9bd0b8 ]
ata_host_start() registers ata_host_stop() as a devres action as soon as it has succeeded, which hands the release of the host resources over to
devres: ->port_stop() and ->host_stop() are then called by the driver core when probe() fails.
ata_host_activate() and ahci_host_activate_multi_irqs() can both fail after ata_host_start() has succeeded, e.g. if devm_request_irq() or ata_host_register() fails, and they return the error with the devres action still registered. A driver which releases the host resources in its probe() error path therefore releases them twice: once itself and once through ->host_stop().
All ahci-platform drivers are in that situation, e.g. ahci_probe() calls ahci_platform_disable_resources() while ahci_host_stop() does the same through devres. This 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.
Add ata_host_undo_start(), which stops the ports and drops the devres action without calling ->host_stop(), and call it from both activation helpers when they fail. Releasing the host resources on failure is then always left to the caller, which is what all callers having a probe() error path already assume.
This changes the semantics for the drivers which implement ->host_stop() while also completely lacking error handling for the activate host call. Add activate host error handling for sata_qstor and sata_fsl. For sata_fsl this also means that hcr_base and host_priv are now released when activating the host fails, which ->host_stop() did not do when ata_host_start() itself failed.
Note that ata_pci_sff_activate_host() is deliberately left as is: none of its callers releases the host resources in its probe() error path, they all rely on ->host_stop() being called by devres, including ata_pci_init_one(), which releases the devres group of the host itself.
---
Depends on <[email protected]>
drivers/ata/libahci.c | 2 + drivers/ata/libahci_platform.c | 4 ++ drivers/ata/libata-core.c | 75 +++++++++++++++++++++++++++++++--- drivers/ata/libata-sff.c | 5 +++ drivers/ata/sata_fsl.c | 6 ++- drivers/ata/sata_qstor.c | 8 +++- include/linux/libata.h | 1 + 7 files changed, 91 insertions(+), 10 deletions(-)
drivers/ata/libahci.c +2 -0
@@ -2662,6 +2662,8 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host, host->ports[i]); } +ata_host_undo_start (host); +return rc; }
drivers/ata/libahci_platform.c +4 -0
@@ -691,6 +691,10 @@ EXPORT_SYMBOL_GPL(ahci_platform_get_resources);* ahci-platform host, note any necessary resources (ie clks, phys, etc.) * must be initialized / enabled before calling this. * +* On failure, ->host_stop() is not called, so the caller has to release the +* resources it enabled (clocks, regulators, resets, PHYs) in its probe() +* error path. +* * RETURNS: * 0 on success otherwise a negative error code */
drivers/ata/libata-core.c +69 -6
114 lines not on this page · raw message
drivers/ata/libata-sff.c +5 -0
@@ -2335,6 +2335,11 @@ EXPORT_SYMBOL_GPL(ata_pci_sff_prepare_host);* hosts. This separate helper is necessary because SFF hosts * use two separate interrupts in legacy mode. * +* Note that, unlike ata_host_activate(), the devres action registered +* by ata_host_start() is kept on failure, i.e. ->host_stop() is called +* by the driver core when probe() fails. All callers of this function +* rely on that, none of them releases the host resources itself. +* * LOCKING: * Inherited from calling layer (may sleep). *
drivers/ata/sata_fsl.c +4 -2
@@ -1490,8 +1490,10 @@ static int sata_fsl_probe(struct platform_device *ofdev)* device discovery process, invoking our port_start() handler & * error_handler() to execute a dummy Softreset EH session */ -ata_host_activate (host, irq, sata_fsl_interrupt,SATA_FSL_IRQ_FLAG , - &sata_fsl_sht); + retval =ata_host_activate (host, irq, sata_fsl_interrupt, +SATA_FSL_IRQ_FLAG , &sata_fsl_sht); +if (retval) + goto error_exit_with_cleanup; host_priv->intr_coalescing.show = fsl_sata_intr_coalescing_show; host_priv->intr_coalescing.store = fsl_sata_intr_coalescing_store;
drivers/ata/sata_qstor.c +6 -2
@@ -584,8 +584,12 @@ static int qs_ata_init_one(struct pci_dev *pdev,qs_host_init (host, board_idx);pci_set_master (pdev); -return ata_host_activate (host, pdev->irq, qs_intr,IRQF_SHARED , - &qs_ata_sht); + rc =ata_host_activate (host, pdev->irq, qs_intr,IRQF_SHARED , + &qs_ata_sht); +if (rc) +qs_host_stop (host); + +return rc; }module_pci_driver (qs_ata_pci_driver);
include/linux/libata.h +1 -0
@@ -1069,6 +1069,7 @@ extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,extern void ata_host_get (struct ata_host *host);extern void ata_host_put (struct ata_host *host);extern int ata_host_start (struct ata_host *host); +void ata_host_undo_start (struct ata_host *host);extern int ata_host_register (struct ata_host *host,struct scsi_host_template *sht); extern int ata_host_activate(struct ata_host *host, int irq,
Signature · 1 line
2.53.0