Re: [PATCH] ata: pata_macio: Do not disable the PCI device on suspend

From: Bjorn Helgaas

Date: Thu Dec 03 2026 - 11:00:17 EST


[+cc Vaibhav]

On Tue, Dec 01, 2026 at 11:17:11PM +0400, Arina Kharlamova wrote:
> pata_macio_suspend() disables the PCI device with pci_disable_device(),
> and pata_macio_reset_hw() enables it again on resume with
> pcim_enable_device(). Since commit f748a07a0b64 ("PCI: Remove legacy
> pcim_release()") every pcim_enable_device() call adds a
> pcim_disable_device() devres action, so each suspend and resume leaves
> one more action behind. On unbind they all run, and every one after
> the first warns about disabling an already disabled device.
>
> The device is enabled with pcim_enable_device() in probe and stays
> managed until unbind, so the driver should not disable and enable it by
> hand. On suspend, clear only the bus master bit, which is all that
> pci_disable_device() did on this hardware, and set it again on resume
> without enabling the device.
>
> Fixes: f748a07a0b64 ("PCI: Remove legacy pcim_release()")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>
> ---
> I found this while checking the other drivers that call
> pcim_enable_device() again on resume, after the discussion of the t7xx
> fix:
> https://lore.kernel.org/all/20261201-s2p-d64-v1-1-c9147b2eedb0@xxxxxxxxxxxx/
>
> Weidong Wang's patch for ata_pci_device_do_resume() fixes the same
> problem in libata core by switching resume to pci_enable_device():
> https://lore.kernel.org/all/20261128-kbug-l080-v1-1-90f7309990ea@xxxxxxxxxxxx/
> Philipp replied there that a driver should either use only pcim_ and
> never undo it, or use only the pci_ functions. This patch takes the
> first way, so the device is no longer disabled on suspend.
>
> With the help of an AI coding assistant (Claude); I reviewed the
> analysis and the fix. Not triggered at runtime. Compile-tested only
> (powerpc pmac32_defconfig), not tested on hardware.
> ---
> drivers/ata/pata_macio.c | 12 ++----------
> 1 file changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/ata/pata_macio.c b/drivers/ata/pata_macio.c
> index a11a1eae2ae8..ba946a4116c3 100644
> --- a/drivers/ata/pata_macio.c
> +++ b/drivers/ata/pata_macio.c
> @@ -788,16 +788,8 @@ static void pata_macio_reset_hw(struct pata_macio_priv *priv, int resume)
>
> /* If resuming a PCI device, restore the config space here */
> if (priv->pdev && resume) {
> - int rc;
> -
> pci_restore_state(priv->pdev);
> - rc = pcim_enable_device(priv->pdev);
> - if (rc)
> - dev_err(&priv->pdev->dev,
> - "Failed to enable device after resume (%d)\n",
> - rc);
> - else
> - pci_set_master(priv->pdev);
> + pci_set_master(priv->pdev);
> }
>
> /* On Kauai, initialize the FCR. We don't perform a reset, doesn't really
> @@ -898,7 +890,7 @@ static int pata_macio_do_suspend(struct pata_macio_priv *priv, pm_message_t mesg
> */
> if (priv->pdev) {
> pci_save_state(priv->pdev);
> - pci_disable_device(priv->pdev);
> + pci_clear_master(priv->pdev);
> }
>
> /* Disable the bus on older machines and the cell on kauai */

This driver uses legacy PCI power management, i.e.,
pci_driver.suspend() and .resume(). If converted to generic power
management (pci_driver.driver.pm hooks), it probably wouldn't need any
of the pci_save_state() and related gunk because the PCI core would
take care of it.

For example:

d5376026f926 ("gpio: bt8xx: use generic power management")
892bb0740b02 ("firewire: ohci: use generic power management")
0aeddbd0cb07 ("via-agp: convert to generic power management")

Bjorn