Re: [PATCH] ata: libata-core: Do not use pcim_enable_device() on PCI resume
From: pstanner@xxxxxxxxxx
Date: Mon Nov 30 2026 - 08:00:55 EST
Hi, thx for the patch.
On Sat, 2026-11-28 at 21:11 -0600, Weidong Wang via B4 Relay wrote:
> From: Weidong Wang <weidongw@xxxxxxxxxxxx>
>
[…]
>
> The fix and this changelog were drafted with AI assistance (Claude Code,
> with a second review by OpenAI Codex), then reviewed by the submitter.
That's evident from the *very* verbose commit message, which I think
should be slimmed down a bit :)
>
> Fixes: f748a07a0b64 ("PCI: Remove legacy pcim_release()")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Weidong Wang <weidongw@xxxxxxxxxxxx>
> ---
> The case of a detach while the device is still disabled (failed resume)
> is left out, see the commit message: it would need a pci_is_enabled()
> check in pcim_disable_device(). I can send that as a separate patch if
> the PCI side agrees.
That's not a good idea. This intertwining makes the API inconsistent.
Instead, pcim_disable_device() should not exist / should be deprecated.
See below.
>
> pata_mpiix never enables the device at probe but uses these helpers;
> that older imbalance is not touched here.
>
> Testing:
> - Compile-tested on x86_64 (allmodconfig, W=1):
> drivers/ata/libata-core.o drivers/ata/pata_cs5520.o; no new warnings.
> - checkpatch.pl --strict: no errors or warnings.
> ---
> drivers/ata/libata-core.c | 8 +++++++-
> drivers/ata/pata_cs5520.c | 12 ++++++++----
> 2 files changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index f41ab71fc9e2..587a393d2753 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -6622,7 +6622,13 @@ int ata_pci_device_do_resume(struct pci_dev *pdev)
> pci_set_power_state(pdev, PCI_D0);
> pci_restore_state(pdev);
>
> - rc = pcim_enable_device(pdev);
> + /*
> + * Balance the pci_disable_device() done on suspend. The devres action
> + * registered by pcim_enable_device() at probe time is still in place,
> + * so do not use pcim_enable_device() here or one more disable action
> + * would be added on every resume.
> + */
> + rc = pci_enable_device(pdev);
So will pcim_enable_device() still be called somewhere else?
I have thought about the pcim_ API a while ago, and my opinion by now
is that drivers must either fully use pcim_, never undoing the actions,
or should *only* use the pci_ functions.
IOW, who wants unmanaged behavior should not use the managed functions.
Especially, functions like pcim_disable_device() should not exist IMO.
If you want to disable the device at any other point in time than
driver unbind, then use pci_enable_device() + pci_disable_device().
> if (rc) {
> dev_err(&pdev->dev,
> "failed to enable device after resume (%d)\n", rc);
> diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
> index 3163c8d9cef5..4337db7f9359 100644
> --- a/drivers/ata/pata_cs5520.c
> +++ b/drivers/ata/pata_cs5520.c
ata_pci_device_do_resume() is used in 28 files. Will the parties other
than cs5520 be affected by this change? That seems quite likely.
> @@ -225,11 +225,15 @@ static int cs5520_reinit_one(struct pci_dev *pdev)
> {
> struct ata_host *host = pci_get_drvdata(pdev);
> u8 pcicfg;
> - int rc;
>
> - rc = ata_pci_device_do_resume(pdev);
> - if (rc)
> - return rc;
> + /*
> + * The device was not disabled on suspend, so do not enable it again
> + * as ata_pci_device_do_resume() would: that would leave the enable
> + * count unbalanced.
> + */
> + pci_set_power_state(pdev, PCI_D0);
> + pci_restore_state(pdev);
> + pci_set_master(pdev);
That change looks suspicious. I would expect it to be unnecessary if
all that were changed in ATA were replacing the pcim_ functions with
the pci_ ones.
Regards
P.