Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2042400imm; Mon, 16 Jul 2018 00:44:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeyUY4hfUtOoEXc6Qu0GIBjQYZUOTRAO1Tq/oWNY+XIwegJ0UqvLcbncyTXg7fhLQJ2WxJl X-Received: by 2002:a17:902:4a0c:: with SMTP id w12-v6mr15836270pld.289.1531727084578; Mon, 16 Jul 2018 00:44:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727084; cv=none; d=google.com; s=arc-20160816; b=wU7/fxN4963es+7CnkklyllZNS3sBiW5eJ/Oc95m1I/Sp3+1b64vs2xPn90OeHhoz/ AJHae94oHvGyyra966HCB69xIfVkP/7kTJ1lfTYZu7UrbbYN+9c0C41FhJd4An8j35ka ZDDsdZIdImJ39X+nCB4tBj/+P7BTACg9ne6wNFnEWmfmyDZEix2KG0jwQPoNDvsgtSn3 1+Y1eES9Ujlt0ZDkcDAIfBwV5/4hy601ui7YyDhoB4Y/ZREBJ+m3CHjeoQQZ756EmBTj 8eu7fLRVAEbaiJM5eHS2hNkUe3lM/mh5EGXGBdobTWz6DTXh0y9VV/rDbhRdb101YXff Cf4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=D1NuS5O2qRo9T0FpWg8O565ecXCr9aumgnih3OqZJgw=; b=e/GUMEwjCm9/BaBqyGKXTxwtnsA96/sEGxARtGTY+VGxHRJVIWwyMoO9YZlQAZvuL4 QY1t3Mp3XseN/l31Bv6lavQeBX372zv10Kl7DwKF7oWVv2L6KkdLB+jB72MVhgl4ruQC ujlifc5UhSPdi+6NSeFgzEtTPL40E9/jz7x5UwlsZSNp6OGvQqu9EIOk0jIEgRHe6xaA gwPP/mzGddMt72T4sUMmvzYgqVnsa7A82AUkuR6kU/DFhgbI7TL7QltjIc7owl29qfv2 DqKN347eRkri57vAS/lgY0p3CsjD5K8/DkJjAGc7nWnYfoJRRb7wog/wG9kAg8zyss/u KBfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5-v6si28525249pgn.105.2018.07.16.00.44.29; Mon, 16 Jul 2018 00:44:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389179AbeGPIJz (ORCPT + 99 others); Mon, 16 Jul 2018 04:09:55 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48068 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388375AbeGPIJy (ORCPT ); Mon, 16 Jul 2018 04:09:54 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1B0D9C03; Mon, 16 Jul 2018 07:43:50 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Wilson , Takashi Iwai Subject: [PATCH 4.9 20/32] ALSA: hda - Handle pm failure during hotplug Date: Mon, 16 Jul 2018 09:36:28 +0200 Message-Id: <20180716073507.082209267@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073504.433996952@linuxfoundation.org> References: <20180716073504.433996952@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Wilson commit aaa23f86001bdb82d2f937c5c7bce0a1e11a6c5b upstream. Obtaining the runtime pm wakeref can fail, especially in a hotplug scenario where i915.ko has been unloaded. If we do not catch the failure, we end up with an unbalanced pm. v2 additions by tiwai: hdmi_present_sense() checks the return value and handle only a negative error case and bails out only if it's really still suspended. Also, snd_hda_power_down() is called at the error path so that the refcount is balanced. Along with it, the spec->pcm_lock is taken outside hdmi_present_sense() in the caller side, so that it won't cause deadlock at reentrace via runtime resume. v3 fix by tiwai: Missing linux/pm_runtime.h is included. References: 222bde03881c ("ALSA: hda - Fix mutex deadlock at HDMI/DP hotplug") Signed-off-by: Chris Wilson Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/hda/patch_hdmi.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -731,8 +732,10 @@ static void check_presence_and_report(st if (pin_idx < 0) return; + mutex_lock(&spec->pcm_lock); if (hdmi_present_sense(get_pin(spec, pin_idx), 1)) snd_hda_jack_report_sync(codec); + mutex_unlock(&spec->pcm_lock); } static void jack_callback(struct hda_codec *codec, @@ -1521,21 +1524,23 @@ static void sync_eld_via_acomp(struct hd static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) { struct hda_codec *codec = per_pin->codec; - struct hdmi_spec *spec = codec->spec; int ret; /* no temporary power up/down needed for component notifier */ - if (!codec_has_acomp(codec)) - snd_hda_power_up_pm(codec); + if (!codec_has_acomp(codec)) { + ret = snd_hda_power_up_pm(codec); + if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) { + snd_hda_power_down_pm(codec); + return false; + } + } - mutex_lock(&spec->pcm_lock); if (codec_has_acomp(codec)) { sync_eld_via_acomp(codec, per_pin); ret = false; /* don't call snd_hda_jack_report_sync() */ } else { ret = hdmi_present_sense_via_verbs(per_pin, repoll); } - mutex_unlock(&spec->pcm_lock); if (!codec_has_acomp(codec)) snd_hda_power_down_pm(codec); @@ -1547,12 +1552,16 @@ static void hdmi_repoll_eld(struct work_ { struct hdmi_spec_per_pin *per_pin = container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work); + struct hda_codec *codec = per_pin->codec; + struct hdmi_spec *spec = codec->spec; if (per_pin->repoll_count++ > 6) per_pin->repoll_count = 0; + mutex_lock(&spec->pcm_lock); if (hdmi_present_sense(per_pin, per_pin->repoll_count)) snd_hda_jack_report_sync(per_pin->codec); + mutex_unlock(&spec->pcm_lock); } static void intel_haswell_fixup_connect_list(struct hda_codec *codec,