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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A240C433F5 for ; Wed, 23 Feb 2022 02:30:46 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 7CDA31916; Wed, 23 Feb 2022 03:29:54 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7CDA31916 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1645583444; bh=wZH01uOAO4UsGv9C+T2IqqCCfADRCqC0wjWMBt/crTc=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RhJylY7buBXkvOIYCRR0/E9c22qmt4qTT/tK1FB3j+V0QPsm0Xg3C54U1FOFrXmKl QuANXKqKcP2yauqa4scKRdseiEAlOYKcUzgvSn9ffgOWbmKUC6M7bAIF9/qTO8ZA1d 4V000OPjdIk4MlUwtOgpJeyZhrqBvM2hyQvpqBEg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id F2D5FF80516; Wed, 23 Feb 2022 03:29:48 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 80AC9F80516; Wed, 23 Feb 2022 03:29:47 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8193FF8019D for ; Wed, 23 Feb 2022 03:29:41 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8193FF8019D Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W1yH16t/" 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 4656161518; Wed, 23 Feb 2022 02:29:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BBFEC36AE5; Wed, 23 Feb 2022 02:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645583380; bh=wZH01uOAO4UsGv9C+T2IqqCCfADRCqC0wjWMBt/crTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1yH16t/wVIxlV/73ovByglOcgNu0kXBIhy+TLWXhOGcWH5zP9dyKERxcUaEhLH53 w+Pw4qnxh2Sre5D+cx7PJ9A26ReIuYplWd6QeBBq4iT2k/YDMgrXvfhLpNpXOVYlUL ZJwSCRIqnD+OSQ+D4Iqcs6hM8euqCkl0TZNluvtAB1HHxjw89ekydzr/FZfe2hEB/6 L299CMSTXSfGdk/zIUswT5DMGT84fZQqmoKq+RI+bDptbWu5F+5kMJdEdlsY+SVZIi mOhrWPe4pyIUS0ZBmxLbF+Ezn2xnjiDpQUwOMxzLUxiyHIL+PQewFDkjIF7TvsX3VQ vg7UcBwt7xuxg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 04/28] ASoC: rt5668: do not block workqueue if card is unbound Date: Tue, 22 Feb 2022 21:29:05 -0500 Message-Id: <20220223022929.241127-4-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220223022929.241127-1-sashal@kernel.org> References: <20220223022929.241127-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 Cc: Sasha Levin , oder_chiou@realtek.com, alsa-devel@alsa-project.org, Kai Vehmanen , lgirdwood@gmail.com, Bard Liao , tiwai@suse.com, Ranjani Sridharan , Pierre-Louis Bossart , Mark Brown , Shuming Fan , =?UTF-8?q?P=C3=A9ter=20Ujfalusi?= X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Kai Vehmanen [ Upstream commit a6d78661dc903d90a327892bbc34268f3a5f4b9c ] The current rt5668_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-2-kai.vehmanen@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/codecs/rt5668.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sound/soc/codecs/rt5668.c b/sound/soc/codecs/rt5668.c index 6ab1a8bc37352..1186ceb5a978e 100644 --- a/sound/soc/codecs/rt5668.c +++ b/sound/soc/codecs/rt5668.c @@ -1022,11 +1022,13 @@ static void rt5668_jack_detect_handler(struct work_struct *work) container_of(work, struct rt5668_priv, jack_detect_work.work); int val, btn_type; - while (!rt5668->component) - usleep_range(10000, 15000); - - while (!rt5668->component->card->instantiated) - usleep_range(10000, 15000); + if (!rt5668->component || !rt5668->component->card || + !rt5668->component->card->instantiated) { + /* card not yet ready, try later */ + mod_delayed_work(system_power_efficient_wq, + &rt5668->jack_detect_work, msecs_to_jiffies(15)); + return; + } mutex_lock(&rt5668->calibrate_mutex); -- 2.34.1 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 8A621C433EF for ; Wed, 23 Feb 2022 02:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236989AbiBWCbU (ORCPT ); Tue, 22 Feb 2022 21:31:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237087AbiBWCaf (ORCPT ); Tue, 22 Feb 2022 21:30:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C45E358387; Tue, 22 Feb 2022 18:29:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id 64CA0B81E01; Wed, 23 Feb 2022 02:29:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BBFEC36AE5; Wed, 23 Feb 2022 02:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645583380; bh=wZH01uOAO4UsGv9C+T2IqqCCfADRCqC0wjWMBt/crTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1yH16t/wVIxlV/73ovByglOcgNu0kXBIhy+TLWXhOGcWH5zP9dyKERxcUaEhLH53 w+Pw4qnxh2Sre5D+cx7PJ9A26ReIuYplWd6QeBBq4iT2k/YDMgrXvfhLpNpXOVYlUL ZJwSCRIqnD+OSQ+D4Iqcs6hM8euqCkl0TZNluvtAB1HHxjw89ekydzr/FZfe2hEB/6 L299CMSTXSfGdk/zIUswT5DMGT84fZQqmoKq+RI+bDptbWu5F+5kMJdEdlsY+SVZIi mOhrWPe4pyIUS0ZBmxLbF+Ezn2xnjiDpQUwOMxzLUxiyHIL+PQewFDkjIF7TvsX3VQ vg7UcBwt7xuxg== 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.15 04/28] ASoC: rt5668: do not block workqueue if card is unbound Date: Tue, 22 Feb 2022 21:29:05 -0500 Message-Id: <20220223022929.241127-4-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220223022929.241127-1-sashal@kernel.org> References: <20220223022929.241127-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 a6d78661dc903d90a327892bbc34268f3a5f4b9c ] The current rt5668_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-2-kai.vehmanen@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/codecs/rt5668.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sound/soc/codecs/rt5668.c b/sound/soc/codecs/rt5668.c index 6ab1a8bc37352..1186ceb5a978e 100644 --- a/sound/soc/codecs/rt5668.c +++ b/sound/soc/codecs/rt5668.c @@ -1022,11 +1022,13 @@ static void rt5668_jack_detect_handler(struct work_struct *work) container_of(work, struct rt5668_priv, jack_detect_work.work); int val, btn_type; - while (!rt5668->component) - usleep_range(10000, 15000); - - while (!rt5668->component->card->instantiated) - usleep_range(10000, 15000); + if (!rt5668->component || !rt5668->component->card || + !rt5668->component->card->instantiated) { + /* card not yet ready, try later */ + mod_delayed_work(system_power_efficient_wq, + &rt5668->jack_detect_work, msecs_to_jiffies(15)); + return; + } mutex_lock(&rt5668->calibrate_mutex); -- 2.34.1