* [PATCH] drm/loongson: Do not add a devres action on every resume
@ 2026-11-30 22:56 Arina Kharlamova via B4 Relay
2026-12-02 6:44 ` Icenowy Zheng
2026-12-03 15:48 ` Bjorn Helgaas
0 siblings, 2 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-11-30 22:56 UTC (permalink / raw)
To: Jianmin Lv, Qianhai Wu, Huacai Chen, Mingcong Bai, Xi Ruoyao,
Icenowy Zheng, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Philipp Stanner,
Bjorn Helgaas, Krzysztof Wilczyński
Cc: dri-devel, stable, Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
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: stable@vger.kernel.org
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
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);
---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-d60-877e4d1f97de
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] drm/loongson: Do not add a devres action on every resume
2026-11-30 22:56 [PATCH] drm/loongson: Do not add a devres action on every resume Arina Kharlamova via B4 Relay
@ 2026-12-02 6:44 ` Icenowy Zheng
2026-12-03 11:17 ` Arina Kharlamova
2026-12-03 15:48 ` Bjorn Helgaas
1 sibling, 1 reply; 5+ messages in thread
From: Icenowy Zheng @ 2026-12-02 6:44 UTC (permalink / raw)
To: arina.kharlamova, Jianmin Lv, Qianhai Wu, Huacai Chen,
Mingcong Bai, Xi Ruoyao, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Philipp Stanner,
Bjorn Helgaas, Krzysztof Wilczy��ski
Cc: dri-devel, stable
在 2026-12-01二的 02:56 +0400,Arina Kharlamova via B4 Relay写道:
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
> 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: stable@vger.kernel.org
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---
> 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))
Will this lead to -EIO when the device is enabled? The && operator would
return the false if the first condition is false.
Should it be `(pci_is_enabled(pdev) || pci_enable_device(pdev))` instead?
Thanks,
Icenowy
> return -EIO;
>
> return lsdc_pm_thaw(dev);
>
> ---
> base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
> change-id: 20261129-s2p-d60-877e4d1f97de
>
> Best regards,
> --
> Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] drm/loongson: Do not add a devres action on every resume
2026-12-02 6:44 ` Icenowy Zheng
@ 2026-12-03 11:17 ` Arina Kharlamova
2026-12-03 11:20 ` Icenowy Zheng
0 siblings, 1 reply; 5+ messages in thread
From: Arina Kharlamova @ 2026-12-03 11:17 UTC (permalink / raw)
To: Icenowy Zheng
Cc: Arina Kharlamova, Jianmin Lv, Qianhai Wu, Huacai Chen,
Mingcong Bai, Xi Ruoyao, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Philipp Stanner,
Bjorn Helgaas, Krzysztof Wilczy里ski,
dri-devel@lists.freedesktop.org, stable@vger.kernel.org
Hi Icenowy,
> Will this lead to -EIO when the device is enabled? The && operator would
> return the false if the first condition is false.
No. When the device is already enabled, !pci_is_enabled() is false, so
the && stops there, pci_enable_device() is not called and the whole
condition is false, so we do not return. -EIO is returned only when the
device is disabled and pci_enable_device() then fails.
With || it would be the other way round: pci_enable_device() would run
exactly when the device is already enabled, which is the extra enable
the patch removes.
Thanks,
Arina
> On 2 Dec 2026, at 10:44, Icenowy Zheng <zhengxingda@iscas.ac.cn> wrote:
>
> This Message Is From an Untrusted Sender
> You have not previously corresponded with this sender.
> 在 2026-12-01二的 02:56 +0400,Arina Kharlamova via B4 Relay写道:
> > From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> >
> > 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: stable@vger.kernel.org
> > Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> > ---
> > 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))
>
> Will this lead to -EIO when the device is enabled? The && operator would
> return the false if the first condition is false.
>
> Should it be `(pci_is_enabled(pdev) || pci_enable_device(pdev))` instead?
>
> Thanks,
> Icenowy
>
> > return -EIO;
> >
> > return lsdc_pm_thaw(dev);
> >
> > ---
> > base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
> > change-id: 20261129-s2p-d60-877e4d1f97de
> >
> > Best regards,
> > --
> > Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] drm/loongson: Do not add a devres action on every resume
2026-12-03 11:17 ` Arina Kharlamova
@ 2026-12-03 11:20 ` Icenowy Zheng
0 siblings, 0 replies; 5+ messages in thread
From: Icenowy Zheng @ 2026-12-03 11:20 UTC (permalink / raw)
To: Arina Kharlamova
Cc: Jianmin Lv, Qianhai Wu, Huacai Chen, Mingcong Bai, Xi Ruoyao,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Philipp Stanner, Bjorn Helgaas,
Krzysztof Wilczy里ski, dri-devel@lists.freedesktop.org,
stable@vger.kernel.org
在 2026-12-03四的 11:17 +0000,Arina Kharlamova写道:
> Hi Icenowy,
>
> > Will this lead to -EIO when the device is enabled? The && operator would
> > return the false if the first condition is false.
>
> No. When the device is already enabled, !pci_is_enabled() is false, so
> the && stops there, pci_enable_device() is not called and the whole
> condition is false, so we do not return. -EIO is returned only when the
> device is disabled and pci_enable_device() then fails.
Well okay I got it reversed.
Sorry for the noise.
Thanks,
Icenowy
>
> With || it would be the other way round: pci_enable_device() would run
> exactly when the device is already enabled, which is the extra enable
> the patch removes.
>
> Thanks,
> Arina
>
>
> > On 2 Dec 2026, at 10:44, Icenowy Zheng <zhengxingda@iscas.ac.cn> wrote:
> >
> > This Message Is From an Untrusted Sender
> > You have not previously corresponded with this sender.
> > 在 2026-12-01二的 02:56 +0400,Arina Kharlamova via B4 Relay写道:
> > > From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> > >
> > > 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: stable@vger.kernel.org
> > > Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> > > ---
> > > 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))
> >
> > Will this lead to -EIO when the device is enabled? The && operator would
> > return the false if the first condition is false.
> >
> > Should it be `(pci_is_enabled(pdev) || pci_enable_device(pdev))` instead?
> >
> > Thanks,
> > Icenowy
> >
> > > return -EIO;
> > >
> > > return lsdc_pm_thaw(dev);
> > >
> > > ---
> > > base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
> > > change-id: 20261129-s2p-d60-877e4d1f97de
> > >
> > > Best regards,
> > > --
> > > Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> >
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/loongson: Do not add a devres action on every resume
2026-11-30 22:56 [PATCH] drm/loongson: Do not add a devres action on every resume Arina Kharlamova via B4 Relay
2026-12-02 6:44 ` Icenowy Zheng
@ 2026-12-03 15:48 ` Bjorn Helgaas
1 sibling, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2026-12-03 15:48 UTC (permalink / raw)
To: Arina Kharlamova
Cc: Jianmin Lv, Qianhai Wu, Huacai Chen, Mingcong Bai, Xi Ruoyao,
Icenowy Zheng, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Philipp Stanner,
Bjorn Helgaas, Krzysztof Wilczyński, dri-devel, stable,
Vaibhav Gupta
[+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: stable@vger.kernel.org
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 15:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 22:56 [PATCH] drm/loongson: Do not add a devres action on every resume Arina Kharlamova via B4 Relay
2026-12-02 6:44 ` Icenowy Zheng
2026-12-03 11:17 ` Arina Kharlamova
2026-12-03 11:20 ` Icenowy Zheng
2026-12-03 15:48 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox