Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1783911pxp; Mon, 7 Mar 2022 02:13:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrdrmFYJu9pysh9NSKLO0erf5A7/lqHyPlivNjXfoKFd9ZtEKTNpFGZ6X7zgqHoH1F7RCz X-Received: by 2002:a17:907:c16:b0:6db:682:c8c9 with SMTP id ga22-20020a1709070c1600b006db0682c8c9mr7053439ejc.153.1646648014166; Mon, 07 Mar 2022 02:13:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646648014; cv=none; d=google.com; s=arc-20160816; b=b8YAnM0547Z6YEwwyc4xW8+TOilD89qKCjDvw/84c6eiXnc6QFaPo2EuCdswKzdTb+ BHpRHr3SCifuUaslBOwY7FlMpEgPQO3MZmuVI6eCxcWZuI5ZUCndJkK12aQ73KKbrz/H eIV7eC2IzmCwG/wkMH/qWhQpGY7ayj+EO7QCIXjYrrIJDsWdJhb/BcuEpGg87mnN06Ka kHNMPvhhBT5gsICgH0TzXTJ6L/AlMGIw3BoX0IbmHqOLukKynWo1bvRGZc2g8KtpBCuH SMJbzc/OkGViTntqQqtP+ubmP9kudmbv5Q7jeA6zm/kc2RMkvyDZfLxkyy4zgEGt6y/u PnKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kJZkt/8PVMYZIAlh1uL/jbsyf40sxgK9YwUWU/9kVqc=; b=0wb+U0Xq1gROggvPuj+49qdaEdcaDfGK+yJt0ZPGmlQvU1hG65vLTtDf2Nq4G9h0pY JU65DSXh7UwkkczDYt759tCKF9gpO29dbHqVNMUI9icyjzAtSFW5+ejQJEuZaUo5Wrbv jswlxvPHjekEo9F5zAiUogp5l4KnzuhM2GC7cMOb2/1CUQzokq/JmLidnqI9W9qPFjlw GjTvK9sts1j1CpjtFRSlP7xGXytXX/kJd+0lTIlELcgTWqLBGlPSwE1f9eIeXzXL+1XZ cbe2newZz8nUOMrDca4JE7QHOD1vNkZ4jaAfKerqsx+JJSOAseKP1eUixriLl6qAQ2AN V1hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ybg7r366; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz22-20020a0564021d5600b00415c2f4884dsi11649818edb.575.2022.03.07.02.13.11; Mon, 07 Mar 2022 02:13:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ybg7r366; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238112AbiCGJos (ORCPT + 99 others); Mon, 7 Mar 2022 04:44:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238114AbiCGJde (ORCPT ); Mon, 7 Mar 2022 04:33:34 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFF086D182; Mon, 7 Mar 2022 01:30:49 -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 A9032B810C6; Mon, 7 Mar 2022 09:30:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECFBFC340E9; Mon, 7 Mar 2022 09:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645406; bh=YHxPyR9nU1QEakJ9ptTge83WeKXRSnbPMpbGOYgU0lw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ybg7r366PAd9qut7m7oN70LlzBYECD7kqEyzv6CTNJDvJGJhF4dL4B7we+VqHmuOL GBjd5JkX1RLqg/Rl0tyMKhu5iCqEa/yDY7Y9MKWO+z+BSmFseicl6exQ/u6UsKfQhj FQzfk8AskKJljgvXhpke1FMI0v/pvN/BxkNkzWMg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kai Vehmanen , Bard Liao , Ranjani Sridharan , Pierre-Louis Bossart , =?UTF-8?q?P=C3=A9ter=20Ujfalusi?= , Shuming Fan , Mark Brown , Sasha Levin Subject: [PATCH 5.10 004/105] ASoC: rt5668: do not block workqueue if card is unbound Date: Mon, 7 Mar 2022 10:18:07 +0100 Message-Id: <20220307091644.307470457@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091644.179885033@linuxfoundation.org> References: <20220307091644.179885033@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 bc69adc9c8b70..e625df57c69e5 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