All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] snd/hda: Only get/put display_power once
@ 2019-04-10  8:17 Chris Wilson
  2019-04-10  8:22 ` Chris Wilson
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Chris Wilson @ 2019-04-10  8:17 UTC (permalink / raw)
  To: intel-gfx; +Cc: Takashi Iwai

While we only allow a single display power reference, the current
acquisition/release is racy and a direct call may run concurrently with
a runtime-pm worker. Prevent the double unreference by atomically
tracking the display_power_active cookie.

Testcase: igt/i915_pm_rpm/module-reload #glk-dsi
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Imre Deak <imre.deak@intel.com>
---
 sound/hda/hdac_component.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/sound/hda/hdac_component.c b/sound/hda/hdac_component.c
index 13915fdc6a54..f0fd0d83c90e 100644
--- a/sound/hda/hdac_component.c
+++ b/sound/hda/hdac_component.c
@@ -66,6 +66,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_set_codec_wakeup);
 void snd_hdac_display_power(struct hdac_bus *bus, unsigned int idx, bool enable)
 {
 	struct drm_audio_component *acomp = bus->audio_component;
+	unsigned long cookie;
 
 	dev_dbg(bus->dev, "display power %s\n",
 		enable ? "enable" : "disable");
@@ -78,26 +79,22 @@ void snd_hdac_display_power(struct hdac_bus *bus, unsigned int idx, bool enable)
 		return;
 
 	if (bus->display_power_status) {
-		if (!bus->display_power_active) {
-			unsigned long cookie = -1;
-
-			if (acomp->ops->get_power)
-				cookie = acomp->ops->get_power(acomp->dev);
+		cookie = -1;
+		if (acomp->ops->get_power)
+			cookie = acomp->ops->get_power(acomp->dev);
 
+		if (!cmpxchg(&bus->display_power_active, 0, cookie)) {
 			snd_hdac_set_codec_wakeup(bus, true);
 			snd_hdac_set_codec_wakeup(bus, false);
-			bus->display_power_active = cookie;
+			cookie = 0;
 		}
 	} else {
-		if (bus->display_power_active) {
-			unsigned long cookie = bus->display_power_active;
+		cookie = xchg(&bus->display_power_active, 0);
+	}
 
-			if (acomp->ops->put_power)
-				acomp->ops->put_power(acomp->dev, cookie);
+	if (cookie && acomp->ops->put_power)
+		acomp->ops->put_power(acomp->dev, cookie);
 
-			bus->display_power_active = 0;
-		}
-	}
 }
 EXPORT_SYMBOL_GPL(snd_hdac_display_power);
 
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-04-10 18:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-10  8:17 [PATCH] snd/hda: Only get/put display_power once Chris Wilson
2019-04-10  8:22 ` Chris Wilson
2019-04-10  9:24 ` ✓ Fi.CI.BAT: success for " Patchwork
2019-04-10 10:09 ` [PATCH] " Takashi Iwai
2019-04-10 10:24   ` Chris Wilson
2019-04-10 10:44     ` Takashi Iwai
2019-04-10 11:03       ` Takashi Iwai
2019-04-10 13:07         ` Chris Wilson
2019-04-10 13:24           ` Takashi Iwai
2019-04-10 10:38 ` ✗ Fi.CI.CHECKPATCH: warning for snd/hda: Only get/put display_power once (rev2) Patchwork
2019-04-10 11:08 ` ✓ Fi.CI.BAT: success " Patchwork
2019-04-10 12:29 ` ✗ Fi.CI.IGT: failure for snd/hda: Only get/put display_power once Patchwork
2019-04-10 12:34 ` ✗ Fi.CI.CHECKPATCH: warning for snd/hda: Only get/put display_power once (rev3) Patchwork
2019-04-10 13:03 ` ✓ Fi.CI.BAT: success " Patchwork
2019-04-10 18:06 ` ✓ Fi.CI.IGT: " Patchwork

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.