Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2483273pxj; Mon, 10 May 2021 04:11:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVY+ymfPSABalqgWfGJQjLgu38SCmvxmMHln6p2aeCMHaEhq4nO9ssWXD7JtB+VS5Rgx0p X-Received: by 2002:a05:6402:312a:: with SMTP id dd10mr28047207edb.384.1620645072568; Mon, 10 May 2021 04:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645072; cv=none; d=google.com; s=arc-20160816; b=RWP3aTjXgdotYL9BK9b9BBNsFpQugo1/dbzMkHl5DKyAnDZIIiq6dNkC/oW7xr4Qif El5Z+CIDV9XDdFvpZWjdnNrEa6f8tmu2ssiHkgiuPoyr/JEOKW5ARbJnqbNHItslNjuZ dcPSJoDwpIiBYq9ohCpAsBg4B2pJX365OceeY1wLMyARdqU+652zIH4kfEm17jzUnpbG n3+PDeQ78QjUBiIkB4rFjR6fpHtZokPs8OJqzVxetDJg1JZbkhyxdEZHz2lJ2byfTt66 Ms7IbuacW3uondl3zzOyKJw6lkQN1KtXngT93UBL3eyfyNL4Uwt6Hc5Ycau5E1+vqbMa idEg== 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=mh5WNNP2d9dHzH7tzGYt0QcgIC/i4wEZX9Fb9tNd69Vv2qvR5ar5rgxCQIJIX3U/46 Vq8Xy18gsYnCh5WMjP3sIXjPQel43M2c2q2QjrbNMtmsnsaEmsHdjNFKJaHpQzijpYEK 81jIKdCjrTcwihap9xY9gf6yWcUJnSO7TNichxjeun+xvQmz4v/P2LHM0GFdF5BWQvDz e0mX5+GPgRXQt88bin0OCp3gukMSkGw7bfG2JOp13pklrl1L32QFtxkAkPWxq15JPVZh JeQ8uMnaS/OXvsEy7rGe8yHGaJjb/OUOnZw6P1W/m4G6VfH/U9wm3FUz7qhP/UohpwrE 81hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dXwv0a6A; 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 o18si13373375edc.137.2021.05.10.04.10.48; Mon, 10 May 2021 04:11: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=dXwv0a6A; 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 S234734AbhEJLFR (ORCPT + 99 others); Mon, 10 May 2021 07:05:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:59374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232235AbhEJKpw (ORCPT ); Mon, 10 May 2021 06:45:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6F51619A8; Mon, 10 May 2021 10:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642991; bh=hFJ4e1Trr9DHNcMpjLkrcuRY5tumV4fL07Gqx5LGkak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dXwv0a6ABxSpG79uTTNzumRNGmJ/A8nal8t4kZa6HuEt2v+r88KLt417J9jNx6kgf Ku28OMFy1TmWIhGNqVIDvU3woRqZ9nf/E8V7MH1vg3AdFnFBWVcKtsN+uSiBo3MCDj Z38cbnghRvkyWdDGMWnfgl65w6dWRuBYEY1kPFyk= 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.10 134/299] extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged Date: Mon, 10 May 2021 12:18:51 +0200 Message-Id: <20210510102009.396002777@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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