From patchwork Mon Feb 7 15:29:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kai Vehmanen X-Patchwork-Id: 540579 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 A29C6C433F5 for ; Mon, 7 Feb 2022 15:39:43 +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 6E90F1841; Mon, 7 Feb 2022 16:38:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6E90F1841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1644248381; bh=IwHdwUlZQAqDo9yE/g9kBLybk9D0paTPFIeJPl4CmVk=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iqi2/32EZgufjUfTQ8tXhJiY1299mOV4OQjYoXD4QqDeI2AJ7DQFeQromg9Tw3DgH qeSphnIlmUzLv6ToY5/HBoqgcXGALR5yK2RM1Wjd7FnP+pVB7keIRd84eBGhngx5gT yyv6NP5C7gEE9al2WlPYM79QZse3R4O1Mxo0XiQA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id EE15CF80240; Mon, 7 Feb 2022 16:38:50 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 81924F80249; Mon, 7 Feb 2022 16:38:49 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id F22E8F800E1 for ; Mon, 7 Feb 2022 16:38:42 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F22E8F800E1 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jpyG3D4u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644248324; x=1675784324; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IwHdwUlZQAqDo9yE/g9kBLybk9D0paTPFIeJPl4CmVk=; b=jpyG3D4uWw1EPQeEVi05Itph43Bsq5y3Y00hDRxTE+AmitkExlZD1IbQ dEtySUhxDPLOajspqWhk5kmooqz2lI0g9TM1U8PP5Hjcd61UCHOlHqejK xrBzCkYZbJ24uAc4MU17Qr8ahw8evGWguLZTOwLlojtpTFTho8fXgPzUE jpafQtHdpRqJ5tcd6LrOEkED8qJNwx+VMQ7ORJ0cPpQzXHVrEIa5c8Tly SPBe19UW2iQZgkhYII6JEmTJPyDUniKTBIJntUC6xc94y8MDBaCZLd0tp E0G7VfqsuNONuNYYf/S6Pis0WqYGdGxC1brOpPtH4sCpRySiT1PxfaoGg w==; X-IronPort-AV: E=McAfee;i="6200,9189,10250"; a="228708977" X-IronPort-AV: E=Sophos;i="5.88,350,1635231600"; d="scan'208";a="228708977" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2022 07:38:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,350,1635231600"; d="scan'208";a="481616910" Received: from eliteleevi.tm.intel.com ([10.237.54.20]) by orsmga003.jf.intel.com with ESMTP; 07 Feb 2022 07:38:38 -0800 From: Kai Vehmanen To: alsa-devel@alsa-project.org, Oder Chiou , broonie@kernel.org Subject: [PATCH 2/3] ASoC: rt5668: do not block workqueue if card is unbound Date: Mon, 7 Feb 2022 17:29:59 +0200 Message-Id: <20220207153000.3452802-2-kai.vehmanen@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207153000.3452802-1-kai.vehmanen@linux.intel.com> References: <20220207153000.3452802-1-kai.vehmanen@linux.intel.com> MIME-Version: 1.0 Cc: kai.vehmanen@linux.intel.com, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.intel.com, ranjani.sridharan@linux.intel.com, Shuming Fan , =?utf-8?q?P=C3=A9ter_Ujfalusi?= 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" 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 --- 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 fb09715bf932..5b12cbf2ba21 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);