From patchwork Mon May 6 09:58:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 163392 Delivered-To: patch@linaro.org Received: by 2002:a92:3d95:0:0:0:0:0 with SMTP id k21csp1650234ilf; Mon, 6 May 2019 02:58:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfVpAuUA5MMZ6BwBvtlEdS8Mohr2/au7oo7LnbnHxgKSIDY1zYhwW7jgypncicZd+6VPtm X-Received: by 2002:a63:534f:: with SMTP id t15mr31346558pgl.445.1557136715129; Mon, 06 May 2019 02:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557136715; cv=none; d=google.com; s=arc-20160816; b=OkIVEi4/TTIdVVNpc+F34Io6DKAM6t5pOFAV9/2Wr+/EFwqaxD3PPeguFJHYj5TUlj mIazA9kJOUFbP/Js2F/qJFA1eDe2DdMvK5a+XYT/nsHYGHxfrs25VHJ56ogSVWXU3Zoy NNtSHjF9VbN8gBs72efm0T9uJMV17ZqpSrmml4m6C9bw7OA35I4f7IuGQvn1TlBPZFou ao+369EGjSO8SpeCkNNnFnEB8tqNbml9jeHGIkTMdvLiXLJuxUCBv3jyzz6PnVtG46T4 d9AYG3KtUfcg/0awBkzX7egmt8Ec6oi0htMI0/bGvRTPOn7FskIL0x8P66TunQSyv2Jz MDGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jFAZLM2HXuFCxb/qpIKx/Zvd6z+9jBXknwydcf65Gow=; b=BlOCCSJC2/JwG5OV4lSzNE16NZoggr2iKhq5idomFcKak9RAOTL/zfn1ST526PJb6q wdFgWw42rMl3QAtYndSbHZpUHzOSSBiNH1rk5VgqChpIwhkfl57HZo5MH8/hW9aDWYzW dIOyAT1ai0S1AiipMGPvw3T8ZkilRxuzUjzYnTg6T46+q+Jep6juFaxCwhiRMMzQwqUG HotTCNV1C9yPw8zQ2+sYbzTlSZgrciBYvP2D0eVguapsG82q5xU1BtUyUTfULwDtwTZO +Admwo9zvPmgNht8aHzmh0GGdr16WxzWDYFznY3At/q9lxJzXnOsPk4Z6eaLGnoGJNgR 5tvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=WouC9aTp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si14353000pls.150.2019.05.06.02.58.34; Mon, 06 May 2019 02:58:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=WouC9aTp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726420AbfEFJ63 (ORCPT + 30 others); Mon, 6 May 2019 05:58:29 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:56050 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbfEFJ61 (ORCPT ); Mon, 6 May 2019 05:58:27 -0400 Received: by mail-wm1-f68.google.com with SMTP id y2so14658078wmi.5 for ; Mon, 06 May 2019 02:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jFAZLM2HXuFCxb/qpIKx/Zvd6z+9jBXknwydcf65Gow=; b=WouC9aTpP+JbWnMYvxrFG/C6chBDo+e5JZjiNsYqbm1PNvq2E6DI/tdFgRaefTjk7i dNjc79J6JQivuiOzumg4tKN6nqc9pthH/ZXoBubgM1z73EO/P6ZuoANyqjt8AFGtzrox Vql+EhiR33zOisnT0IV4X/4e/92L5bH6IDmnx+zE3q6H5MoMovyn0VzUkQNR0OE90imA eT4RaWKVBYJJ80/h7P2uUdpWyPEvjwJ/iuM/hwMegTQpfDHfRPtK0uzeM1OoO9aVsaLZ trtYy11H5oiseOjLJjgK+D80szm9pmKtydFxdC4+PqhUTs3pbDpBur1EV1ejfQ49DpP6 S0BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jFAZLM2HXuFCxb/qpIKx/Zvd6z+9jBXknwydcf65Gow=; b=YTv8YQ40b3p0JEJct6fCniCyiMaUxsRBTZHnGCfGHxFQddfSg1dVrQkb7+uButhiTu bVkaqjggR/dckIQRW32+JG/2MdFtKPsCySIBpPJV16vmRbPWR0a6t3nq78iVcol1wKnd HhxM5ee2/FJvf+/qndfPp/Zvrqh8VnuyMXcbYOtCqTheRkIM0m+NcFdj9RtLODmjYB5n Kf3iyKdLe8lvjTMTaEO2sv8Ynlfs91Xy5TbATJXzk27z5cQFhN4QwrVcC1+3br7F56eO 69dCfA7f51S46TWS7GIMNLnT5OeyJDiu8rrH8JTG5/iEl/IWfXThGn2oC7w00pLHqEQ/ 1qog== X-Gm-Message-State: APjAAAUzpGihjG/ad/VV5YNik82wYAwele9RRO2CxAmBs/C37R335Evb 4LIe3gtCBjnWZ/wn+UKQS0z+rIKikh0= X-Received: by 2002:a1c:67c1:: with SMTP id b184mr15691569wmc.12.1557136704663; Mon, 06 May 2019 02:58:24 -0700 (PDT) Received: from boomer.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id c10sm23409791wrd.69.2019.05.06.02.58.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 May 2019 02:58:24 -0700 (PDT) From: Jerome Brunet To: Mark Brown , Liam Girdwood Cc: Jerome Brunet , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, patchwork-bot+notify@kernel.org Subject: [PATCH v2 2/4] ASoC: hdmi-codec: remove reference to the current substream Date: Mon, 6 May 2019 11:58:13 +0200 Message-Id: <20190506095815.24578-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190506095815.24578-1-jbrunet@baylibre.com> References: <20190506095815.24578-1-jbrunet@baylibre.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the hdmi-codec is on a codec-to-codec link, the substream pointer it receives is completely made up by snd_soc_dai_link_event(). The pointer will be different between startup() and shutdown(). The hdmi-codec complains when this happens even if it is not really a problem. The current_substream pointer is not used for anything useful apart from getting the exclusive ownership of the device. Remove current_substream pointer and replace the exclusive locking mechanism with a simple variable and some atomic operations. Signed-off-by: Jerome Brunet --- sound/soc/codecs/hdmi-codec.c | 58 ++++++++++------------------------- 1 file changed, 16 insertions(+), 42 deletions(-) -- 2.20.1 diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index eb31d7eddcbf..4d32f93f6be6 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -280,11 +280,10 @@ struct hdmi_codec_priv { struct hdmi_codec_pdata hcd; struct snd_soc_dai_driver *daidrv; struct hdmi_codec_daifmt daifmt[2]; - struct mutex current_stream_lock; - struct snd_pcm_substream *current_stream; uint8_t eld[MAX_ELD_BYTES]; struct snd_pcm_chmap *chmap_info; unsigned int chmap_idx; + unsigned long busy; }; static const struct snd_soc_dapm_widget hdmi_widgets[] = { @@ -392,42 +391,22 @@ static int hdmi_codec_chmap_ctl_get(struct snd_kcontrol *kcontrol, return 0; } -static int hdmi_codec_new_stream(struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) -{ - struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); - int ret = 0; - - mutex_lock(&hcp->current_stream_lock); - if (!hcp->current_stream) { - hcp->current_stream = substream; - } else if (hcp->current_stream != substream) { - dev_err(dai->dev, "Only one simultaneous stream supported!\n"); - ret = -EINVAL; - } - mutex_unlock(&hcp->current_stream_lock); - - return ret; -} - static int hdmi_codec_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); int ret = 0; - ret = hdmi_codec_new_stream(substream, dai); - if (ret) - return ret; + ret = test_and_set_bit(0, &hcp->busy); + if (ret) { + dev_err(dai->dev, "Only one simultaneous stream supported!\n"); + return -EINVAL; + } if (hcp->hcd.ops->audio_startup) { ret = hcp->hcd.ops->audio_startup(dai->dev->parent, hcp->hcd.data); - if (ret) { - mutex_lock(&hcp->current_stream_lock); - hcp->current_stream = NULL; - mutex_unlock(&hcp->current_stream_lock); - return ret; - } + if (ret) + goto err; } if (hcp->hcd.ops->get_eld) { @@ -437,17 +416,18 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream, if (!ret) { ret = snd_pcm_hw_constraint_eld(substream->runtime, hcp->eld); - if (ret) { - mutex_lock(&hcp->current_stream_lock); - hcp->current_stream = NULL; - mutex_unlock(&hcp->current_stream_lock); - return ret; - } + if (ret) + goto err; } /* Select chmap supported */ hdmi_codec_eld_chmap(hcp); } return 0; + +err: + /* Release the exclusive lock on error */ + clear_bit(0, &hcp->busy); + return ret; } static void hdmi_codec_shutdown(struct snd_pcm_substream *substream, @@ -455,14 +435,10 @@ static void hdmi_codec_shutdown(struct snd_pcm_substream *substream, { struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); - WARN_ON(hcp->current_stream != substream); - hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data); - mutex_lock(&hcp->current_stream_lock); - hcp->current_stream = NULL; - mutex_unlock(&hcp->current_stream_lock); + clear_bit(0, &hcp->busy); } static int hdmi_codec_hw_params(struct snd_pcm_substream *substream, @@ -761,8 +737,6 @@ static int hdmi_codec_probe(struct platform_device *pdev) return -ENOMEM; hcp->hcd = *hcd; - mutex_init(&hcp->current_stream_lock); - hcp->daidrv = devm_kcalloc(dev, dai_count, sizeof(*hcp->daidrv), GFP_KERNEL); if (!hcp->daidrv)