linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Hans de Goede <hdegoede@redhat.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Charles Keepax <ckeepax@opensource.cirrus.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Lee Jones <lee.jones@linaro.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.9 03/24] extcon: arizona: Fix some issues when HPDET IRQ fires after the jack has been unplugged
Date: Mon,  3 May 2021 12:42:31 -0400	[thread overview]
Message-ID: <20210503164252.2854487-3-sashal@kernel.org> (raw)
In-Reply-To: <20210503164252.2854487-1-sashal@kernel.org>

From: Hans de Goede <hdegoede@redhat.com>

[ 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 <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 4c0b6df8b5dd..1d06d99b8bd9 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;
 	}
@@ -672,7 +671,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 			   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) {
@@ -680,7 +679,9 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 		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


  parent reply	other threads:[~2021-05-03 17:07 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 16:42 [PATCH AUTOSEL 4.9 01/24] scsi: target: pscsi: Fix warning in pscsi_complete_cmd() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 02/24] media: ite-cir: check for receive overflow Sasha Levin
2021-05-03 16:42 ` Sasha Levin [this message]
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 04/24] media: media/saa7164: fix saa7164_encoder_register() memory leak bugs Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 05/24] media: gspca/sq905.c: fix uninitialized variable Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 06/24] media: pci: saa7164: Rudimentary spelling fixes in the file saa7164-types.h Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 07/24] power: supply: Use IRQF_ONESHOT Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 08/24] drm/bridge/analogix/anx78xx: Setup encoder before registering connector Sasha Levin
2021-05-06 17:14   ` Lyude Paul
2021-05-07 10:59     ` Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 09/24] drm/bridge/analogix/anx78xx: Cleanup on error in anx78xx_bridge_attach() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 10/24] scsi: qla2xxx: Always check the return value of qla24xx_get_isp_stats() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 11/24] scsi: scsi_dh_alua: Remove check for ASC 24h in alua_rtpg() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 12/24] media: em28xx: fix memory leak Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 13/24] clk: socfpga: arria10: Fix memory leak of socfpga_clk on error return Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 14/24] power: supply: generic-adc-battery: fix possible use-after-free in gab_remove() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 15/24] power: supply: s3c_adc_battery: fix possible use-after-free in s3c_adc_bat_remove() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 16/24] media: adv7604: fix possible use-after-free in adv76xx_remove() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 17/24] media: i2c: adv7511-v4l2: fix possible use-after-free in adv7511_remove() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 18/24] media: i2c: adv7842: fix possible use-after-free in adv7842_remove() Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 19/24] media: dvb-usb: fix memory leak in dvb_usb_adapter_init Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 20/24] media: gscpa/stv06xx: fix memory leak Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 21/24] drm/msm/mdp5: Configure PP_SYNC_HEIGHT to double the vtotal Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 22/24] drm/amdgpu: fix NULL pointer dereference Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 23/24] scsi: lpfc: Fix crash when a REG_RPI mailbox fails triggering a LOGO response Sasha Levin
2021-05-03 16:42 ` [PATCH AUTOSEL 4.9 24/24] scsi: libfc: Fix a format specifier Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210503164252.2854487-3-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=cw00.choi@samsung.com \
    --cc=hdegoede@redhat.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).