[+cc Vaibhav, who's done a lot of PCI suspend/resume rework]
On Tue, Dec 01, 2026 at 02:56:08AM +0400, Arina Kharlamova wrote:
> lsdc_pm_suspend() disables the PCI device with pci_disable_device() and
> lsdc_pm_resume() enables it again with pcim_enable_device(). Since
> commit f748a07a0b64 ("PCI: Remove legacy pcim_release()") the managed
> variant registers a new pcim_disable_device() devres action on each
> call, so every suspend and resume cycle leaves one more action on the
> device. When the driver is unbound, all of them run: the first one
> drops the enable count to zero, the next one triggers the "disabling
> already-disabled device" warning, and each further one makes the count
> more negative.
>
> The device is already managed from lsdc_pci_probe(). Use the plain
> pci_enable_device() in the resume path so that it only balances the
> pci_disable_device() done at suspend. lsdc_pm_resume() is also the
> .restore callback, and .poweroff does not disable the device, so only
> enable it when it is disabled.
>
> Fixes: f748a07a0b64 ("PCI: Remove legacy pcim_release()")
> Cc: [email protected]
> Signed-off-by: Arina Kharlamova <[email protected]>
> ---
> Found by checks derived from the spec2patch kernel API specifications,
> with the help of an AI coding assistant (Claude); I reviewed the
> analysis and the fix.
> ---
> drivers/gpu/drm/loongson/lsdc_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/loongson/lsdc_drv.c
> b/drivers/gpu/drm/loongson/lsdc_drv.c
> index 5a13df31eb90..e5b7b34d739e 100644
> --- a/drivers/gpu/drm/loongson/lsdc_drv.c
> +++ b/drivers/gpu/drm/loongson/lsdc_drv.c
> @@ -428,7 +428,7 @@ static int lsdc_pm_resume(struct device *dev)
>
> pci_restore_state(pdev);
>
> - if (pcim_enable_device(pdev))
> + if (!pci_is_enabled(pdev) && pci_enable_device(pdev))
> return -EIO;
>
> return lsdc_pm_thaw(dev);
Taking a step back, why do lsdc_pm_suspend() and lsdc_pm_resume() need
those PCI things in the first place? The PCI core should take care of
the pci_save_state() and power management already, without having to
do it in the driver.
Bjorn