From patchwork Mon Mar 22 16:37:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Louis Bossart X-Patchwork-Id: 406187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61498C433C1 for ; Mon, 22 Mar 2021 16:39:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 941ED61983 for ; Mon, 22 Mar 2021 16:39:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 941ED61983 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 23A90852; Mon, 22 Mar 2021 17:38:52 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 23A90852 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616431182; bh=85L6X2n4pYlF2a8S2JW5e2BcOyYjdKNIhWYZsWZ18yo=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dr6R5KFClGvsR+VAvwNWuv/K2nRdUu/b0IrMsmbH393eowuJxJVtOHVZ4FZ+Y4fc/ JdUmtLc+4uZasWPQQ2VBknjbuzChSPVrjJiH5e+q7sC21f8r8C1wrE8nVOs+0xdv5o lbhpa50PPiXzL+cOud1T17/95mNjZC243dm4764g= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 68C5BF801EB; Mon, 22 Mar 2021 17:38:05 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1BCE2F802E3; Mon, 22 Mar 2021 17:38:00 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 E8A6EF80107 for ; Mon, 22 Mar 2021 17:37:46 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E8A6EF80107 IronPort-SDR: dk0VVfJ+w59qsEfxt5e/dMiEX5cA5jT2v4BTqIUu+aFgWax1LHmo7828X/4efO7M5uMK+XebwP Xgz1ohYlWi/A== X-IronPort-AV: E=McAfee;i="6000,8403,9931"; a="210376606" X-IronPort-AV: E=Sophos;i="5.81,269,1610438400"; d="scan'208";a="210376606" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2021 09:37:42 -0700 IronPort-SDR: X+E8/3bCDBkD+5KJQml426Q0k7b4+Jas1Ib7L5D1lJFXN74hRlV1ZEyirLaom+mf41yFmteZM6 rRIkdFLIddNA== X-IronPort-AV: E=Sophos;i="5.81,269,1610438400"; d="scan'208";a="407899081" Received: from josemari-mobl1.amr.corp.intel.com (HELO pbossart-mobl3.intel.com) ([10.209.40.21]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2021 09:37:41 -0700 From: Pierre-Louis Bossart To: alsa-devel@alsa-project.org Subject: [PATCH 2/8] ASoC: SOF: core: harden shutdown helper Date: Mon, 22 Mar 2021 11:37:22 -0500 Message-Id: <20210322163728.16616-3-pierre-louis.bossart@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210322163728.16616-1-pierre-louis.bossart@linux.intel.com> References: <20210322163728.16616-1-pierre-louis.bossart@linux.intel.com> MIME-Version: 1.0 Cc: Libin Yang , Kai Vehmanen , tiwai@suse.de, Pierre-Louis Bossart , Ranjani Sridharan , broonie@kernel.org 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" When the probe is handled in a workqueue, we must use cancel_work_sync() in the shutdown helper to avoid possible race conditions. We must also take care of possible errors happening in a probe workqueue or during pm_runtime resume (called e.g. before shutdown for PCI devices). We should really only try to access hardware registers and initiate IPCs if the DSP is fully booted. Fixes: daff7f1478e12 ("ASoC: SOF: add snd_sof_device_shutdown() helper for shutdown") Signed-off-by: Pierre-Louis Bossart Reviewed-by: Ranjani Sridharan Reviewed-by: Kai Vehmanen Reviewed-by: Libin Yang --- sound/soc/sof/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 495295a34c3a..7005353602c4 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -400,7 +400,13 @@ int snd_sof_device_shutdown(struct device *dev) { struct snd_sof_dev *sdev = dev_get_drvdata(dev); - return snd_sof_shutdown(sdev); + if (IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)) + cancel_work_sync(&sdev->probe_work); + + if (sdev->fw_state == SOF_FW_BOOT_COMPLETE) + return snd_sof_shutdown(sdev); + + return 0; } EXPORT_SYMBOL(snd_sof_device_shutdown);