All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Niklas Cassel" <cassel@kernel.org>
Cc: dlemoal@kernel.org, cassel@kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCH] ata: libata: Do not leave ata_host_stop() registered when activation fails
Date: Wed, 09 Sep 2026 19:07:38 +0000	[thread overview]
Message-ID: <20260909190738.DAB3F1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260909185035.3130774-2-cassel@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Bypassing `->host_stop()` on activation failure via `ata_host_undo_start()` breaks legacy PCI and OF drivers that rely on devres for hardware and resource cleanup, leading to state/memory leaks and interrupt storms.

Pre-existing issues:
- [High] Missing IRQ cleanup in ahci_host_activate_multi_irqs error path leads to active interrupts during hardware teardown.
--

commit 33ab74bb11edbc6ab549b2a41db1917c6750487f
Author: Niklas Cassel <cassel@kernel.org>

ata: libata: Do not leave ata_host_stop() registered when activation fails

ata_host_start() registers ata_host_stop() as a devres action. This patch
adds ata_host_undo_start() to stop the ports and drop the devres action
without calling ->host_stop() when activation helpers fail, returning
resource release responsibility to the caller.

> diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
> index 6d72eb017b498..7ac1fcdd6d0d7 100644
> --- a/drivers/ata/libahci.c
> +++ b/drivers/ata/libahci.c
> @@ -2723,11 +2723,20 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host,
>  				0, pp->irq_desc, host->ports[i]);
>  
>  		if (rc)
> -			return rc;
> +			goto undo_start;
>  		ata_port_desc_misc(host->ports[i], irq);
>  	}
>  
> -	return ata_host_register(host, sht);
> +	rc = ata_host_register(host, sht);
> +	if (rc)
> +		goto undo_start;
> +
> +	return 0;
> +
> +undo_start:
> +	ata_host_undo_start(host);
> +
> +	return rc;

[Severity: High]
This is a pre-existing issue, but by not freeing the successfully requested
IRQs in this error path before returning, can we cause a kernel panic?

If devm_request_irq() fails for one port, or if ata_host_register() fails,
this jumps to undo_start and returns an error without freeing the IRQs.

The caller (ahci_platform_init_host) and platform driver will then disable
clocks and PHYs via ahci_platform_disable_resources(). If a pending interrupt
fires before the generic devres cleanup eventually frees the IRQs, the
interrupt handler (ahci_multi_irqs_intr_hard) will attempt to access unclocked
AHCI registers.

>  }
>  
>  /**
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index 59e87b987d73e..4c0ee207f4c64 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
[ ... ]
> +void ata_host_undo_start(struct ata_host *host)
> +{
> +	int i;
> +
> +	if (!(host->flags & ATA_HOST_STARTED))
> +		return;
> +
> +	for (i = 0; i < host->n_ports; i++) {
> +		struct ata_port *ap = host->ports[i];
> +
> +		if (ap->ops->port_stop)
> +			ap->ops->port_stop(ap);
> +	}
> +
> +	/*
> +	 * Drop the action added by ata_host_start() without calling it.
> +	 * It does not exist if neither ->port_stop() nor ->host_stop() is
> +	 * implemented, in which case there is nothing to drop.
> +	 */
> +	devres_destroy(host->dev, ata_host_stop, NULL, NULL);

[Severity: High]
Does bypassing ->host_stop() here break legacy PCI and OF drivers that rely
entirely on the devres action for hardware and resource cleanup?

For instance, sata_qstor enables hardware interrupts in qs_ata_init_one():

	qs_host_init(host, board_idx);
	pci_set_master(pdev);
	return ata_host_activate(host, pdev->irq, qs_intr, IRQF_SHARED,
				 &qs_ata_sht);

If ata_host_activate() fails, the driver relies on qs_host_stop() to disable
interrupts. By skipping ->host_stop(), wouldn't unhandled hardware interrupts
remain enabled, potentially causing an interrupt storm?

Similarly, sata_nv programs ADMA configuration into PCI registers before
calling ata_pci_sff_activate_host() in nv_init_one(). If activation fails,
nv_adma_host_stop() is bypassed. Does this leak the hardware ADMA
configuration state?

Also, in sata_fsl_probe(), the return value of ata_host_activate() is ignored,
leaving the device bound despite activation failure. With ->host_stop()
bypassed, will this cause resources to leak on unbind?

> +
> +	host->flags &= ~ATA_HOST_STARTED;
> +}
> +EXPORT_SYMBOL_GPL(ata_host_undo_start);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909185035.3130774-2-cassel@kernel.org?part=1

      reply	other threads:[~2026-09-09 19:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 18:50 [PATCH] ata: libata: Do not leave ata_host_stop() registered when activation fails Niklas Cassel
2026-09-09 19:07 ` 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=20260909190738.DAB3F1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.