stable.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: "Kai Vehmanen" <kai.vehmanen@linux.intel.com>,
	"Bard Liao" <yung-chuan.liao@linux.intel.com>,
	"Ranjani Sridharan" <ranjani.sridharan@linux.intel.com>,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
	"Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Shuming Fan" <shumingf@realtek.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Sasha Levin" <sashal@kernel.org>,
	oder_chiou@realtek.com, lgirdwood@gmail.com, perex@perex.cz,
	tiwai@suse.com, alsa-devel@alsa-project.org
Subject: [PATCH AUTOSEL 5.16 07/30] ASoC: rt5682: do not block workqueue if card is unbound
Date: Tue, 22 Feb 2022 21:27:56 -0500	[thread overview]
Message-ID: <20220223022820.240649-7-sashal@kernel.org> (raw)
In-Reply-To: <20220223022820.240649-1-sashal@kernel.org>

From: Kai Vehmanen <kai.vehmanen@linux.intel.com>

[ Upstream commit 4c33de0673ced9c7c37b3bbd9bfe0fda72340b2a ]

The current rt5682_jack_detect_handler() assumes the component
and card will always show up and implements an infinite usleep
loop waiting for them to show up.

This does not hold true if a codec interrupt (or other
event) occurs when the card is unbound. The codec driver's
remove  or shutdown functions cannot cancel the workqueue due
to the wait loop. As a result, code can either end up blocking
the workqueue, or hit a kernel oops when the card is freed.

Fix the issue by rescheduling the jack detect handler in
case the card is not ready. In case card never shows up,
the shutdown/remove/suspend calls can now cancel the detect
task.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Shuming Fan <shumingf@realtek.com>
Link: https://lore.kernel.org/r/20220207153000.3452802-3-kai.vehmanen@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/codecs/rt5682.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/rt5682.c b/sound/soc/codecs/rt5682.c
index 7e6e2f26accd0..e3643ae6de66d 100644
--- a/sound/soc/codecs/rt5682.c
+++ b/sound/soc/codecs/rt5682.c
@@ -1092,11 +1092,13 @@ void rt5682_jack_detect_handler(struct work_struct *work)
 	struct snd_soc_dapm_context *dapm;
 	int val, btn_type;
 
-	while (!rt5682->component)
-		usleep_range(10000, 15000);
-
-	while (!rt5682->component->card->instantiated)
-		usleep_range(10000, 15000);
+	if (!rt5682->component || !rt5682->component->card ||
+	    !rt5682->component->card->instantiated) {
+		/* card not yet ready, try later */
+		mod_delayed_work(system_power_efficient_wq,
+				 &rt5682->jack_detect_work, msecs_to_jiffies(15));
+		return;
+	}
 
 	dapm = snd_soc_component_get_dapm(rt5682->component);
 
-- 
2.34.1


  parent reply	other threads:[~2022-02-23  2:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23  2:27 [PATCH AUTOSEL 5.16 01/30] HID: apple: Set the tilde quirk flag on the Wellspring 5 and later Sasha Levin
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 02/30] mac80211_hwsim: report NOACK frames in tx_status Sasha Levin
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 03/30] mac80211_hwsim: initialize ieee80211_tx_info at hw_scan_work Sasha Levin
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 04/30] i2c: bcm2835: Avoid clock stretching timeouts Sasha Levin
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 05/30] ASoC: rt5682s: do not block workqueue if card is unbound Sasha Levin
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 06/30] ASoC: rt5668: " Sasha Levin
2022-02-23  2:27 ` Sasha Levin [this message]
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 08/30] regulator: core: fix false positive in regulator_late_cleanup() Sasha Levin
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 09/30] Input: clear BTN_RIGHT/MIDDLE on buttonpads Sasha Levin
2022-02-23  2:27 ` [PATCH AUTOSEL 5.16 10/30] btrfs: get rid of warning on transaction commit when using flushoncommit Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 11/30] KVM: arm64: vgic: Read HW interrupt pending state from the HW Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 12/30] block: loop:use kstatfs.f_bsize of backing file to set discard granularity Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 13/30] tipc: fix a bit overflow in tipc_crypto_key_rcv() Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 14/30] cifs: do not use uninitialized data in the owner/group sid Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 15/30] cifs: fix double free race when mount fails in cifs_get_root() Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 16/30] USB: zaurus: support another broken Zaurus Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 17/30] HID: amd_sfh: Handle amd_sfh work buffer in PM ops Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 18/30] HID: amd_sfh: Add functionality to clear interrupts Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 19/30] HID: amd_sfh: Add interrupt handler to process interrupts Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 20/30] cifs: modefromsids must add an ACE for authenticated users Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 21/30] selftests/seccomp: Fix seccomp failure by adding missing headers Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 22/30] drm/amd/pm: correct UMD pstate clocks for Dimgrey Cavefish and Beige Goby Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 23/30] selftests/ftrace: Do not trace do_softirq because of PREEMPT_RT Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 24/30] dmaengine: shdma: Fix runtime PM imbalance on error Sasha Levin
2022-02-24 22:39   ` Pavel Machek
2022-02-25  6:25     ` 刘永志
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 25/30] i2c: cadence: allow COMPILE_TEST Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 26/30] i2c: imx: " Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 27/30] i2c: qup: " Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 28/30] CDC-NCM: avoid overflow in sanity checking Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 29/30] net: usb: cdc_mbim: avoid altsetting toggling for Telit FN990 Sasha Levin
2022-02-23  2:28 ` [PATCH AUTOSEL 5.16 30/30] block-map: add __GFP_ZERO flag for alloc_page in function bio_copy_kern 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=20220223022820.240649-7-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=shumingf@realtek.com \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /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).