Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2039375imm; Mon, 16 Jul 2018 00:40:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeRKQPyVTwgo4MmWYgc6JbQV3TqggwwpuF4tXHUj+nzgo1vY9SuB07mpxBBdNspvY4UTaDt X-Received: by 2002:a65:62d8:: with SMTP id m24-v6mr13565005pgv.307.1531726818913; Mon, 16 Jul 2018 00:40:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531726818; cv=none; d=google.com; s=arc-20160816; b=sWeFhMcAH4DuvYSD5nOKoHUksj36Q6LCz6JdlOdEKm+lrpa1sIGs9pz1Ti2RSSNY+9 433JIh+5O7pMWotXKi9Pjw0g7Ulh1AZCFm7yqPIxnB5YUB2cq8YutNywxhXC9s85XTY7 bHa+Z7Xc+6Kc+q20CKAmtyP61PZAcoUfMd7zNLLDFjpnS3pBycYNGSsyxWaRoZkJjsqg mUZMLazDoRoThIBhom7E1FGYwBUDJlWuFg7sAwCEjEcqDq5PfXdYZeNwB7lZvZEz7+t1 Da2+lvY7DMgcLnAbjSy/NJzBwMcNT2iujftQd1l0Hk0pG7Mo3l41hdDdqai6Ocqw8sIu nBqQ== 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=Z5fG019iLVlRW/SolJW/tFP3UALmyFOu0J6/P1yX0wk=; b=uk+MXt/T4m+3hOfZdIlaVm1Vllhvklg8xjVtZ7xW5rdaFi3zEGBUPjT2VmLUDYPhSI ZqgCvhUj3UXfd0ZIdLMEdoyANq2UNjTrzYmFgHbG0ASietOtjWQxjSxfZCd+WuhT83oz GwAelqQl0NxO3Yrpj5Yy/Gr8t/K5RvBv5/UfihuX9xLObixdfAJ1Nxq7uAMl0jc4tcnC eXupWc7Z+EcMgNeEayiYA1OZ/1xb2w+vaZmfpLduPJCGG8s9bV1HffNdl9iyov70boLd zYd7rIcw491zZyGkFEUptSwUdrDCKbCDdCVWhWyb8ECgGnF7jojoFp+od+ER0U0LE6Hp oQxg== 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 t62-v6si22026883pgd.485.2018.07.16.00.40.03; Mon, 16 Jul 2018 00:40:18 -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 S1732565AbeGPIE2 (ORCPT + 99 others); Mon, 16 Jul 2018 04:04:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46908 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729883AbeGPIE1 (ORCPT ); Mon, 16 Jul 2018 04:04:27 -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 F082FC03; Mon, 16 Jul 2018 07:38:25 +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.17 34/67] ALSA: hda - Handle pm failure during hotplug Date: Mon, 16 Jul 2018 09:35:03 +0200 Message-Id: <20180716073448.508530063@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073443.294323458@linuxfoundation.org> References: <20180716073443.294323458@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.17-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 @@ -764,8 +765,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, @@ -1628,21 +1631,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); @@ -1654,12 +1659,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,