Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp302264pxj; Thu, 20 May 2021 09:38:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB4tI98lYlnKeRNl0CYyoHNRx3gtN0JMzqe+1FKrvUvyAmWAdMXFftpjfRFOjZ6NlSDn0n X-Received: by 2002:a17:906:57c3:: with SMTP id u3mr5743990ejr.162.1621528737513; Thu, 20 May 2021 09:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621528737; cv=none; d=google.com; s=arc-20160816; b=uVIeYoHJukkFDNxk5y0tr2SOf6WICbYFvN1MTV61WsKUq3iom0UEf5rA0MwCLUXwfK ZI9YnziLIoH9aAjgNxb1fpfdacc23+0UqYDg84mXIOvoVTEK/iRYHUJsBMzBjyDRA97N 8vcRreTGLWWFrARHZ3rhDZiKi8Z3HhLka+lRMCHrJjXpwPPwIfab/EbjY/LWkRVwWFnI vjrEaqc0Hrh/2tQ42QtyaW6MgZMWfzYnfNHw8pEVJgyUn732nYMI+fxboExtfGOLysQR GombYp2eSYMf3DduP1EM35W0xDhMwjACHSTDyUAhaPrCmjAhdK3vw2/7LI5bI7YA7/54 vrsg== 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=Rf975kQo9NgbQzzAnWTIWc3mn4MfmvuXaIEaY9bXdy8=; b=I7d6DmbCLNfvYVK45EU9hSKTfxa24XY5+UK8Etf6KhQnC3WYiC9cS4Dxcln+DY2BIZ 6syaTxzDfrm3utvhnd/4QJxaUbSlnsOcONWeHV+huSxXpwS5bburm1BRwrKOlIsGHKK7 n4caMqj6ALRwJHoXzE23XkUeUDhWnJPqS96AfGjBpYbNUVEzSed0JnsjUJLUIell0Kxy uBk31VzioPoX+NObWTVAD/xCjoyBc0DkbXcLJDEHH+9GOAjmVEr4R682src6eleFacPS w8fKICjIpU1Pa8QjpAr/kkH/0goi+3gI+vG/BVTqzNOc2mAf6vtY8r722I+fO1vmB69d xKwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HB4bDLoT; 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 op2si3047794ejb.68.2021.05.20.09.38.33; Thu, 20 May 2021 09:38:57 -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=HB4bDLoT; 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 S232984AbhETJkd (ORCPT + 99 others); Thu, 20 May 2021 05:40:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:41292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbhETJip (ORCPT ); Thu, 20 May 2021 05:38:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1A97E6141C; Thu, 20 May 2021 09:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503053; bh=9m8i2hDsaKJLlIMzMD1ZAvL1znc/2jK0+OLLzrbpAQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HB4bDLoT2EhA1c7lteYZoJUk6APim4X6NdrTiUswWOg1vVEF+9BMY3EE6CnvH8BkH qO3rL9aRW8cNlmCgjtkn79ZSxE4o9L/AeOKhjHlHRC49gtQ44W0RUXuzBCbSbW/VKl jrKQF/XBLb9xXY+l9H9KY8E1xTR4QWFclqfx4ESw= 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.19 048/425] extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged Date: Thu, 20 May 2021 11:16:57 +0200 Message-Id: <20210520092133.005378736@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 9327479c719c..c857120c00d9 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