Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2989415pxj; Mon, 17 May 2021 15:02:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKWwCNJb8pb4U9fNUovzpPSte3amGzY9L70qUMnRsKpZSPsWGoLLsxM0XUkKB3YK6MMgCT X-Received: by 2002:a17:906:456:: with SMTP id e22mr2041851eja.427.1621288964627; Mon, 17 May 2021 15:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621288964; cv=none; d=google.com; s=arc-20160816; b=d9nwxQiLtaM6ShBFeZkRn10V3HVRthkg8G7EjT971K2/p3Hkxb7nKJQymPpZKQDA+o czsq0ZXuyMgbL8k8AcT+7QzqvjWD1+5xhZreZxlG7YtLiF7+DGfs02/HDA5GEOl9cwGx Nb8rRTuQ5XwuaLHYUoIxol9kLKr76gZMiW01ZDLwVIKmgl2X8ABxOFIMH1YoF2YQUa10 kYb+4RRTMEoKgiO88Pf+HNcC4uiRqeWJ6mjftddAat2Na6DIX52rFDkozOvM56/SyuyQ Ms5WrAKUw5IIChQHprZlvg2ogfTd9/w3yb/KeIH0RMir8csvPzxdCQ4g6NMJ9ltvv52p FrSQ== 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=FQcVh0gic4iM8PTNJ8hrezYeFafK5XuTMqBrCuGn6Ww=; b=ox1bj0Fvde6fH9AsFfluNzAN/W/zLarrVV/hYr0Ea7o/hCM/zZO3/dry4+alu7uQLP RruaKTtqe9PJ4Pr82YChf+Haod65V3145taMHSLJkshO0SVdtGWviXYJKbSon1i06NJW 65jvMH1x5jS7162lQ7kI2CZwcB7LrlyAdOHStI659tR7oYQWMhN1uPuC058a3FBT3cXW xLwg4qyYyRD/orbCpP5X0pANxLze3aWHWn1IzydQnSqNaDaIHooo8kKdrSaXTzLlTrcq KEgLAEcRHpE/uRq2vqFaPsEt81Z5cCF/UcheD4GA54UvXTQguG8cFPdbYC0gjDA/lwFE ijGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OxGagDtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b22si9188983edw.115.2021.05.17.15.02.21; Mon, 17 May 2021 15:02:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OxGagDtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238367AbhEQOMI (ORCPT + 99 others); Mon, 17 May 2021 10:12:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:60286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238348AbhEQOKD (ORCPT ); Mon, 17 May 2021 10:10:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C0EE613B5; Mon, 17 May 2021 14:07:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260433; bh=crQZifefxFB5zTrNmQ8E/W5S9724KgP2XqK90+Y+VD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OxGagDtJcx/PtqYwXedIAGFvA73k+7QI157ubafDleruwC8y261IRxar5QG//kUMT Ta8ggXEk9RdODjZoe1uJHRgZitmT74VD61Iisw0zNA8hqVbmx+TH9zy+urgtaDx9Ht 6GzYjtmEUx+vvV1KvARtI5vymRu25G3lrIChUYEA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Linh Phung T. Y." , Kuninori Morimoto , Mark Brown , Sasha Levin Subject: [PATCH 5.12 080/363] ASoC: rsnd: call rsnd_ssi_master_clk_start() from rsnd_ssi_init() Date: Mon, 17 May 2021 15:59:06 +0200 Message-Id: <20210517140305.301559380@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuninori Morimoto [ Upstream commit a122a116fc6d8fcf2f202dcd185173a54268f239 ] Current rsnd needs to call .prepare (P) for clock settings, .trigger for playback start (S) and stop (E). It should be called as below from SSI point of view. P -> S -> E -> P -> S -> E -> ... But, if you used MIXer, below case might happen (2) 1: P -> S ---> E -> ... 2: P ----> S -> ... (1) (3) P(1) setups clock, but E(2) resets it. and starts playback (3). In such case, it will reports "SSI parent/child should use same rate". rsnd_ssi_master_clk_start() which is the main function at (P) was called from rsnd_ssi_init() (= S) before, but was moved by below patch to rsnd_soc_dai_prepare() (= P) to avoid using clk_get_rate() which shouldn't be used under atomic context. commit 4d230d1271064 ("ASoC: rsnd: fixup not to call clk_get/set under non-atomic") Because of above patch, rsnd_ssi_master_clk_start() is now called at (P) which is for non atomic context. But (P) is assuming that spin lock is *not* used. One issue now is rsnd_ssi_master_clk_start() is checking ssi->xxx which should be protected by spin lock. After above patch, adg.c had below patch for other reasons. commit 06e8f5c842f2d ("ASoC: rsnd: don't call clk_get_rate() under atomic context") clk_get_rate() is used at probe() timing by this patch. In other words, rsnd_ssi_master_clk_start() is no longer using clk_get_rate() any more. This means we can call it from rsnd_ssi_init() (= S) again which is protected by spin lock. This patch re-move it to under spin lock, and solves 1. checking ssi->xxx without spin lock issue. 2. clk setting / device start / device stop race condition. Reported-by: Linh Phung T. Y. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/875z0x1jt5.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sh/rcar/ssi.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c index d0ded427a836..a2f8138d40c7 100644 --- a/sound/soc/sh/rcar/ssi.c +++ b/sound/soc/sh/rcar/ssi.c @@ -507,10 +507,15 @@ static int rsnd_ssi_init(struct rsnd_mod *mod, struct rsnd_priv *priv) { struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); + int ret; if (!rsnd_ssi_is_run_mods(mod, io)) return 0; + ret = rsnd_ssi_master_clk_start(mod, io); + if (ret < 0) + return ret; + ssi->usrcnt++; rsnd_mod_power_on(mod); @@ -1060,13 +1065,6 @@ static int rsnd_ssi_pio_pointer(struct rsnd_mod *mod, return 0; } -static int rsnd_ssi_prepare(struct rsnd_mod *mod, - struct rsnd_dai_stream *io, - struct rsnd_priv *priv) -{ - return rsnd_ssi_master_clk_start(mod, io); -} - static struct rsnd_mod_ops rsnd_ssi_pio_ops = { .name = SSI_NAME, .probe = rsnd_ssi_common_probe, @@ -1079,7 +1077,6 @@ static struct rsnd_mod_ops rsnd_ssi_pio_ops = { .pointer = rsnd_ssi_pio_pointer, .pcm_new = rsnd_ssi_pcm_new, .hw_params = rsnd_ssi_hw_params, - .prepare = rsnd_ssi_prepare, .get_status = rsnd_ssi_get_status, }; @@ -1166,7 +1163,6 @@ static struct rsnd_mod_ops rsnd_ssi_dma_ops = { .pcm_new = rsnd_ssi_pcm_new, .fallback = rsnd_ssi_fallback, .hw_params = rsnd_ssi_hw_params, - .prepare = rsnd_ssi_prepare, .get_status = rsnd_ssi_get_status, }; -- 2.30.2