From patchwork Mon Apr 29 13:29:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 163026 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp1887925ill; Mon, 29 Apr 2019 06:30:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSAThrT4GhKQHQU1zE8T5GS1oV2OIfFwZhldmV8qtQ4eN+RftSVYL4H80CGX0JJZbTGdzt X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr61973139plb.190.1556544607722; Mon, 29 Apr 2019 06:30:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556544607; cv=none; d=google.com; s=arc-20160816; b=Y/HtCXFaPtHudn6IJi3yxnwpMmjaTafcRgKPIw4sF7BrWTzFhyOC2Qximv2TsuXTt8 jan/MgIJxl4k6FoNnBOe5/rDDkRUW1hH7CGJavrd6uAmbYfR3EHgR29pS3G2tOshAkn1 8an9ReE5EO+U9p6nZptFKUXrKV4LkopGGB5rXwFnxMzsJirZra68NQcFdv2+XW1cCnT+ KRMf10kvFXyojwJiGe5xm5ZfLgT92xgkbzSVt8/GP7axCdozq4+Mz/0YCesomP9iF/wT 5YOjz/SFfjd9EtBtAqUyJUB90eCwrcA8rwKC3ANTYfM8zPPvHhqtMZsWPaLQaGTMUYoS zKdg== 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=Hd6mJetFt+bYMfDoxeUlaN2SLCfgBvFwtxKuQlMcFOY=; b=grKnRPDIaRj6kbVgpt2PXxvrcWJOWhpLp4nNWmj9O1Q7dkFAk/jGo9BWrNnaCfNpcP GyJrp+brDBa34k2QHJ0z5fc5m3tWSNS1yqFCOy0vPi8qgXquF77Hz/+VoEOBkGqE7CGf cDXzrmh01Ti07zZuh9SKrch0ffO7ZFnadsze3m+TnKeP8hQeLRldyJnBv9S5Zm95ajz6 NIIJLFRaBG/kWOzS0xWuDgxtsbDVjjj48Q7E4vRccyWtN53HwTOUwWkku90SjQAoSzJc hW+vBcWgyeRe3RAiSvSOuxTK4B+xvNzqk+a/rpM/IL8N6WafJykI1QKQwwH76RXbHSF+ LFKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=C4SN6Sjb; 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 p14si31403818pgb.292.2019.04.29.06.30.07; Mon, 29 Apr 2019 06:30:07 -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=C4SN6Sjb; 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 S1728311AbfD2NaG (ORCPT + 30 others); Mon, 29 Apr 2019 09:30:06 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39488 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728251AbfD2N3z (ORCPT ); Mon, 29 Apr 2019 09:29:55 -0400 Received: by mail-wm1-f68.google.com with SMTP id n25so822992wmk.4 for ; Mon, 29 Apr 2019 06:29:53 -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=Hd6mJetFt+bYMfDoxeUlaN2SLCfgBvFwtxKuQlMcFOY=; b=C4SN6SjbEVh9brvwWa9I0k53I0+eUkzThi7Z4tRSiWcMVwsyOZkS2Ri2zTPFrRU1hA EX/Qwh90q+DdtDX5XD3rlaN050hOPFVqbmNEVbyos3JbwA6mzccSmjWIaZPBUpywAIPb +n0lfVLB+RwIP/HVA+qrZJlAooCK1oDs9FWOJ/UH1ymIGBpoFQJcmHKkt34UQ6B/S5M1 qakEvdkdQC1+yhn3HOWd4JlDgMDcPRolzMqRbMQzZhlFoFyM2+m045V8Tze+YtdDT7hQ RH8eFWekONdGWfyo9zvBOhVFQmPyzzQt+1SuV6+7hosSTQVBEy+lVvumrFEhB2BWSJvV AbTA== 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=Hd6mJetFt+bYMfDoxeUlaN2SLCfgBvFwtxKuQlMcFOY=; b=VbCWlnux6zJcvouWVNaK+NaI5Xq0qAJuRkAsdL3TcGbOBW/sStFNoSPLo8bPYdGoiI NhynOntihwRu0vdPugz7DH+hp4Tz/UAMzZJrcFjW3rG7wdXfrY6xxii/u+NX2yFwK28J oYngPml+y0J1QYC8pxbz4cN62wLE+YjcJfSpcax+pHPFijqF5ZBVEVvDEYV4t9Sgl+SG 2ZPZaxhWdc55a2rAmiH7PxYiSOburHRnipDfDraNZOn9aM9sYt96KJgLOC8WwKX5kby5 3VmzAFs/WY3gJcUiDM33TWst2WQWrwzQOZbu/+JkYn1BXOZmd7YyqS0N+rWAI8ARBPDY NxNw== X-Gm-Message-State: APjAAAV8BjBMcLbDFXoSDfby2sWQPxe1YGhJuwlGcRq0hyE71d7lKRdM PWEnrgnElmv0T9osVGPQsOkY7A== X-Received: by 2002:a1c:3845:: with SMTP id f66mr16599583wma.97.1556544592685; Mon, 29 Apr 2019 06:29:52 -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 s17sm2857593wra.94.2019.04.29.06.29.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Apr 2019 06:29:52 -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 4/6] ASoC: hdmi-codec: remove reference to the current substream Date: Mon, 29 Apr 2019 15:29:41 +0200 Message-Id: <20190429132943.16269-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190429132943.16269-1-jbrunet@baylibre.com> References: <20190429132943.16269-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 780f2008b271..717d0949f8b4 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, @@ -766,8 +742,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)