Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp405046pxj; Thu, 20 May 2021 12:03:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5khQsG8EgNZoYnSFbbC0AGu6Fft9Jz4F4w/l28MAhvMvVP2yjox/86ToCnyFUyA8sRNy6 X-Received: by 2002:a02:a1dd:: with SMTP id o29mr8190763jah.112.1621537392974; Thu, 20 May 2021 12:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621537392; cv=none; d=google.com; s=arc-20160816; b=LmoErbnAsF5J7rHTJXRz7lTDOyoRd2Mtb40uWC4BSPTIrFh1p4ngMMpKhaDizPW66S elBoBB+lgPzXjhiZS5W7iVynV9Bb20JhNVLjDSM0EWOSBaa68q/0ABYZQeN5fLE3VmLJ ZwxgQ64RvwQ7mfR2qR/O9JxQdqdKPYEhJiTyYlg/26D0k4zoKypuP4n0yy/5WTy85d0l ODiu8hySopCZyOHzdMILoc11VYbecdL++qeeU+oR+WThqDJad7M6DFZO+2zCOFs4NGGr zgE+622U9Q6y455gmN5Ux/iB/PpmRBhHNAUpE9pi7dVQ3UR0IsO9pku+tF5PfLQPb3s7 pbJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k8iIHRwKvNIpWt4QEJYwt7jhk2ACBEEHe4tnebh2CKc=; b=qibCrPVSOAHYW62RJeD18qSczyf/8y/ggAN4O9XMYrt2FyiR7dBGlGe1UjWScRrDb2 SqRR6Hkx2z/JfSTm37EmVkRKil9X7rK/QcVJ3ZMPvPSmQAzjhRUOKFZ0ysnQ5PC0a93U awAfw7Hhtwm7saePPBYceqxuCqznEw8XpZzBXL31+EesgGQWAtWdkpPqgqDFF15qRaJi VD6FJh0x/lWINjrKLeFKLK0/rlbZiJ3V0dFoBtPpaQC36vjTfL9ZuhcXepEz5In+2W3A i4KvmBxZERqEwfUdb4PTjhSHDzqHvdB04gRSjxXUTVKOo+Lzi/XdCTVv6ylXrD3cVTJm 2SAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ovhmHK95; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j5si3122308ilr.135.2021.05.20.12.02.59; Thu, 20 May 2021 12:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ovhmHK95; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237009AbhETKbC (ORCPT + 99 others); Thu, 20 May 2021 06:31:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:51816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234928AbhETKTG (ORCPT ); Thu, 20 May 2021 06:19:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E9338613E4; Thu, 20 May 2021 09:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504005; bh=2l6TBRvwqJktH3yy1j+MLDCT/5w1WPdIGj/Adx5mGy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ovhmHK95cKO8kjAmF8WDoeLlL7gwvNdJCxtnhQT9jelUGpGaWe4/terOireld2pCJ z8P2Vtzf5Fw9P4LOFSioU1kmFcbE+Ay1CtLmOSrVMfK6qk3TGpZr3QYcPVXoBLW/8r tCPJpMPoz0N07jmQBOmkMKybCLVcCHsDu6NdJCTY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Andy Shevchenko , Charles Keepax , Chanwoo Choi , Lee Jones , Sasha Levin Subject: [PATCH 4.14 050/323] extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged Date: Thu, 20 May 2021 11:19:02 +0200 Message-Id: <20210520092121.823022189@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans de Goede [ Upstream commit c309a3e8793f7e01c4a4ec7960658380572cb576 ] When the jack is partially inserted and then removed again it may be removed while the hpdet code is running. In this case the following may happen: 1. The "JACKDET rise" or ""JACKDET fall" IRQ triggers 2. arizona_jackdet runs and takes info->lock 3. The "HPDET" IRQ triggers 4. arizona_hpdet_irq runs, blocks on info->lock 5. arizona_jackdet calls arizona_stop_mic() and clears info->hpdet_done 6. arizona_jackdet releases info->lock 7. arizona_hpdet_irq now can continue running and: 7.1 Calls arizona_start_mic() (if a mic was detected) 7.2 sets info->hpdet_done Step 7 is undesirable / a bug: 7.1 causes the device to stay in a high power-state (with MICVDD enabled) 7.2 causes hpdet to not run on the next jack insertion, which in turn causes the EXTCON_JACK_HEADPHONE state to never get set This fixes both issues by skipping these 2 steps when arizona_hpdet_irq runs after the jack has been unplugged. Signed-off-by: Hans de Goede Reviewed-by: Andy Shevchenko Acked-by: Charles Keepax Tested-by: Charles Keepax Acked-by: Chanwoo Choi Signed-off-by: Lee Jones Signed-off-by: Sasha Levin --- drivers/extcon/extcon-arizona.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 4937a404fee8..2cfd5db75625 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -602,7 +602,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) struct arizona *arizona = info->arizona; int id_gpio = arizona->pdata.hpdet_id_gpio; unsigned int report = EXTCON_JACK_HEADPHONE; - int ret, reading; + int ret, reading, state; bool mic = false; mutex_lock(&info->lock); @@ -615,12 +615,11 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) } /* If the cable was removed while measuring ignore the result */ - ret = extcon_get_state(info->edev, EXTCON_MECHANICAL); - if (ret < 0) { - dev_err(arizona->dev, "Failed to check cable state: %d\n", - ret); + state = extcon_get_state(info->edev, EXTCON_MECHANICAL); + if (state < 0) { + dev_err(arizona->dev, "Failed to check cable state: %d\n", state); goto out; - } else if (!ret) { + } else if (!state) { dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n"); goto done; } @@ -673,7 +672,7 @@ done: ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); /* If we have a mic then reenable MICDET */ - if (mic || info->mic) + if (state && (mic || info->mic)) arizona_start_mic(info); if (info->hpdet_active) { @@ -681,7 +680,9 @@ done: info->hpdet_active = false; } - info->hpdet_done = true; + /* Do not set hp_det done when the cable has been unplugged */ + if (state) + info->hpdet_done = true; out: mutex_unlock(&info->lock); -- 2.30.2