Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2548839pxj; Mon, 10 May 2021 05:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxq0peutOWsSJizReFlGdyZmTCNiG3YyB2amEAJlDLlvink1htIOIjKJUg0N/1url3mrv2 X-Received: by 2002:a17:907:7b9f:: with SMTP id ne31mr25476475ejc.139.1620650522480; Mon, 10 May 2021 05:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620650522; cv=none; d=google.com; s=arc-20160816; b=dOK6e1HXC0lWE20WwPLShcqs9B/6FBSwN875AqUqC2oVia3MJKUZwPflomoEEYB35w wOenqGLQ3ajE3qEoTazFTcUQ2UvWSZJ3TRm/4hWiDQy99dZrPbhwcl8q/KYPmOWCSWt2 U1Jy5H+d/4Jc4Mt8B9Sy5c/Q3y9kHoXzjYMyjhxL8Jx//2ruW0YQdRtC3iED1sHDi+8M Tag0EL61fRqxfCG09rJb2AdQ48K+HP91GEjizSjVdmpNCy71jsvCSAy3oMZeNvOm+dzf PMCFYAXNg5cwvA3OeZ3k+h5WutLnZZFdMqyxpALMuEhDmjrg9wvNR3sa0QJZqud1xAR8 LCXg== 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=GauGGx2B2BfJyU42fhlbGyI+BowPK2fLH1BxzfG2dZY=; b=oRR+5hytNCRO2qViqYwsEMTqyndXlp3Dfuz4tPFjd+CfSqCxerAHqcTxG4ZYGMEbmG wxWzrYrzNlzb+VF9fu43Y1Zo23QSxhUCKUeNoam+oIDE3lH6oAN6v5ehcyODlxhsehIy XDWJEYDsaWoWskchZpgzzLSdRHqFKvJb+o3y58zJbb+F/1L9ncGYu+AhbCCrQeXmv+e+ ixbEXas9YNzEtN7UL8FtK554QiwRHZ8167mOET7fBPEPjodRPeOs5wuZtHE9cVIRI/QT Bh0DZ3b6jtnUM7VDy+7gMAaN2OjUp+W5nbx3KMDhbBnPuvO/IadhZg2Ewk8B1wWzT42q XUIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Dzb04j9O; 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 e14si10658461edz.320.2021.05.10.05.41.39; Mon, 10 May 2021 05:42:02 -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=Dzb04j9O; 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 S1343527AbhEJM3x (ORCPT + 99 others); Mon, 10 May 2021 08:29:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:46932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233324AbhEJLI4 (ORCPT ); Mon, 10 May 2021 07:08:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 30D8161A1D; Mon, 10 May 2021 11:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644665; bh=hFJ4e1Trr9DHNcMpjLkrcuRY5tumV4fL07Gqx5LGkak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dzb04j9OTV86jgnXUThYWdzq4DL1RUTYBq0fNORGYalybjOhx0UCg9bvrq1I/0vHA XXsV3eV5K0ejENVNbE84fhSarffBbfMH/Csmy5t1FdQ9WrqPcNKqw2E3YFyfTWAHSA E0hFGZMTEMz3i+x9OfkLGwOlUf/pm8tiYL2xHFLE= 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 5.12 174/384] extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged Date: Mon, 10 May 2021 12:19:23 +0200 Message-Id: <20210510102020.619018608@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@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 aae82db542a5..f7ef247de46a 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -601,7 +601,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); @@ -614,12 +614,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; } @@ -667,7 +666,7 @@ done: gpio_set_value_cansleep(id_gpio, 0); /* 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) { @@ -675,7 +674,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