From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84598C433F5 for ; Wed, 23 Feb 2022 02:28:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236874AbiBWC3W (ORCPT ); Tue, 22 Feb 2022 21:29:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236827AbiBWC3F (ORCPT ); Tue, 22 Feb 2022 21:29:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEEE945796; Tue, 22 Feb 2022 18:28:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 49D2C61503; Wed, 23 Feb 2022 02:28:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 337DBC340E8; Wed, 23 Feb 2022 02:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645583316; bh=vcokKHRdWLknFV2KbvAUKivjwJmcjUZEyBX083tQPL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H85qsTg1/eAxZp/iNFXDccvC47YKa3O7pj6r9ePly4NNhZ4bXWRGoHJ+riNCPWoeN 1j4Qyhdg+Kiho+xKXJ8zGrnJDEPzCUzh8Df+m5QaMzjKHQxgXlBeLmSlvknkP9bLLy pLaRTBkl77T/j70LXLCVwp55a68YwHsX0iaEXnxphPK7EA9ryo4hYZf7dN7j1zpZz7 3wlFmtriNoo5vIe9Jmwjdc2pgF5mA48lc0+nId9+jhX7Yiz/G1vHEpgcIJr0IZMy8s H2jqiTI9tUgP08hvvE+LWIGcJ5zYl9UgoPxPsDRFLUbvHeb8rXBlvxreLZd+GvBg+v 8s/PnMBkUtPYQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kai Vehmanen , Bard Liao , Ranjani Sridharan , Pierre-Louis Bossart , =?UTF-8?q?P=C3=A9ter=20Ujfalusi?= , Shuming Fan , Mark Brown , Sasha Levin , 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 Message-Id: <20220223022820.240649-7-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220223022820.240649-1-sashal@kernel.org> References: <20220223022820.240649-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kai Vehmanen [ 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 Reviewed-by: Bard Liao Reviewed-by: Ranjani Sridharan Reviewed-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Shuming Fan Link: https://lore.kernel.org/r/20220207153000.3452802-3-kai.vehmanen@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- 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