From patchwork Wed Apr 10 08:17:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10893437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5AE914DB for ; Wed, 10 Apr 2019 08:17:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92C3F289F5 for ; Wed, 10 Apr 2019 08:17:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86C26289F7; Wed, 10 Apr 2019 08:17:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9359F289F5 for ; Wed, 10 Apr 2019 08:17:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A1D7389304; Wed, 10 Apr 2019 08:17:56 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id E0645892FF for ; Wed, 10 Apr 2019 08:17:54 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 16192718-1500050 for multiple; Wed, 10 Apr 2019 09:17:36 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 10 Apr 2019 09:17:33 +0100 Message-Id: <20190410081733.22271-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] snd/hda: Only get/put display_power once X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Takashi Iwai Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Takashi Iwai Cc: Imre Deak Reported-by: Chris Wilson Signed-off-by: Takashi Iwai Reviewed-by: Chris Wilson --- 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);