From patchwork Mon Feb 7 15:30:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kai Vehmanen X-Patchwork-Id: 541845 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 5EA50C433EF for ; Mon, 7 Feb 2022 15:40:14 +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 40F2E1866; Mon, 7 Feb 2022 16:39:22 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 40F2E1866 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1644248412; bh=meH7z7nrUfTvpLjwaj/Q3CO+U0gl866RXS+WQMwHa+Q=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BVbw/O9ZAn6z7jlEv3PatMudbpjYn4kYxJ7Lz4fZSqRl+5zWQ8DX/1wJUWDIlb5CH W4mUL+7fSVT+jHEclH9NkLPVXDCKQtIfLTDTQ5b8lhQ8LThbSxEOffBmtPn9UyDYgB b3kZvvzUNmpEvpQiEtPFTwFJYVBlBeN214h5HJFE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4D708F80246; Mon, 7 Feb 2022 16:38:53 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8F255F804D2; Mon, 7 Feb 2022 16:38:51 +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 189A2F800E9 for ; Mon, 7 Feb 2022 16:38:44 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 189A2F800E9 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l2b0JPE3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644248326; x=1675784326; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=meH7z7nrUfTvpLjwaj/Q3CO+U0gl866RXS+WQMwHa+Q=; b=l2b0JPE32rElOe3DKCbrhEdlZVb7N9K+EFU/tsW7hAvpUr6zlRIG2NZL rvQF2qCDAi8xP94v3pfc6Oo10OP70NNN8xuKjSohLq6vXZz7TX9CbwvLx hpuTVl67zeRZBm8xhOYUk7x1TX9otSbp0QzZlZRv6+o8LTOnCY2hxL7ON aGcT89P8J6afHhxg9C++wfvfgwOq+2f5B503jMNHD/n4JNYybnKEmJzSh IWmS/ZLEl5kr8S8JEHbFHuCSFNF2awrSpSNyie0/DWqC0+fJDO/4RXHB3 XO9O5i7tdaVIud5E2h2F7QERH2ecjmTkZnlEbM1LZ/IZpEOzJxkphkBrn Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10250"; a="228708988" X-IronPort-AV: E=Sophos;i="5.88,350,1635231600"; d="scan'208";a="228708988" 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:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,350,1635231600"; d="scan'208";a="481616915" Received: from eliteleevi.tm.intel.com ([10.237.54.20]) by orsmga003.jf.intel.com with ESMTP; 07 Feb 2022 07:38:41 -0800 From: Kai Vehmanen To: alsa-devel@alsa-project.org, Oder Chiou , broonie@kernel.org Subject: [PATCH 3/3] ASoC: rt5682: do not block workqueue if card is unbound Date: Mon, 7 Feb 2022 17:30:00 +0200 Message-Id: <20220207153000.3452802-3-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 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 --- 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 415ec564c82e..4b164a04d4dc 100644 --- a/sound/soc/codecs/rt5682.c +++ b/sound/soc/codecs/rt5682.c @@ -1096,11 +1096,13 @@ void rt5682_jack_detect_handler(struct work_struct *work) container_of(work, struct rt5682_priv, jack_detect_work.work); 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; + } mutex_lock(&rt5682->jdet_mutex); mutex_lock(&rt5682->calibrate_mutex);