Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp258538ybx; Tue, 5 Nov 2019 23:32:36 -0800 (PST) X-Google-Smtp-Source: APXvYqxkv8E6wFYWlLRZLsWGmFId5OemkMovBqFSC7cb1nwg1MSI+wLdVzHxPgbeWOpIKSr3K0jM X-Received: by 2002:a05:6402:339:: with SMTP id q25mr1137839edw.80.1573025556795; Tue, 05 Nov 2019 23:32:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573025556; cv=none; d=google.com; s=arc-20160816; b=ogbXJMD3XClBGR5FFa/tfmtv83G4vBjYuMoWSgib3JmqFQuAS0jeE+l+jZpo7J3iby nmcOyef8lDIdMzEqf948pGN4MWKIyzjiM5HXVKWNQsCs7l6d9fYW1jC5hye6r6Nd50qP IEcN4Un93ZqkyHAwpPnNGQmA/MOTBbX8dwlVBtLuFKzSVegj5SbEUf1n+ttKRNImwAIy 1h+VgD/ctPBnrI2FozTrZW+x5q1jYnzDsxYkzEhNB7Wh8PVAs8UnMswVZxXcIxFK8Nar eWjr2fc4bU6EIHVbtBQeXLDHL2kT59UqdLaVDLZ4UugqY8NIiDuqtSHRFEcbnnbgUdhX Q9Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from; bh=Afs4uI5WOMo1YRVqMsF0RcuwOoERNoCO61ArgiEnjEU=; b=InVn6yLWb5+9Pnwm4KrSzgBhxpGHi+FUROksE0/ePjjrrfR+UF6FYG57HK2skvIzdZ cpTV5qQLU+4Nq9NfTwMmoPgtnN771W3VKBzEJgrfRt2Cdm+aFzeHgKn57cYzcDTI4M+o 772Z03W+VbvgxvAa2gmLz2t3dHBqwb4flcWmrbko9zZw14Cla2BeR4xGatnngIIDpR9d fauRpX+CZXuIXWvPSs6foDyCXZdlmNR6upS0gzo9pSigdVtxW9A7gDIo0zcpgY1mug0D 4IjGZuU16AE630+pq48gx7F9yGduzCHJLG2y2ZZNtBHcol0ssvXbjpnWIGQIfToq8ODL kjMw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b7si12233026ede.12.2019.11.05.23.32.12; Tue, 05 Nov 2019 23:32:36 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731357AbfKFH3Y (ORCPT + 99 others); Wed, 6 Nov 2019 02:29:24 -0500 Received: from inva021.nxp.com ([92.121.34.21]:40496 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729683AbfKFH3X (ORCPT ); Wed, 6 Nov 2019 02:29:23 -0500 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 16AB42001C8; Wed, 6 Nov 2019 08:29:21 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 8CC4E20013E; Wed, 6 Nov 2019 08:29:16 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id AD12340285; Wed, 6 Nov 2019 15:29:10 +0800 (SGT) From: Shengjiu Wang To: timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: fsl_audmix: Add spin lock to protect tdms Date: Wed, 6 Nov 2019 15:27:45 +0800 Message-Id: <1573025265-31852-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Audmix support two substream, When two substream start to run, the trigger function may be called by two substream in same time, that the priv->tdms may be updated wrongly. The expected priv->tdms is 0x3, but sometimes the result is 0x2, or 0x1. Signed-off-by: Shengjiu Wang --- sound/soc/fsl/fsl_audmix.c | 6 ++++++ sound/soc/fsl/fsl_audmix.h | 1 + 2 files changed, 7 insertions(+) diff --git a/sound/soc/fsl/fsl_audmix.c b/sound/soc/fsl/fsl_audmix.c index c7e4e9757dce..a1db1bce330f 100644 --- a/sound/soc/fsl/fsl_audmix.c +++ b/sound/soc/fsl/fsl_audmix.c @@ -286,6 +286,7 @@ static int fsl_audmix_dai_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) { struct fsl_audmix *priv = snd_soc_dai_get_drvdata(dai); + unsigned long lock_flags; /* Capture stream shall not be handled */ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) @@ -295,12 +296,16 @@ static int fsl_audmix_dai_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + spin_lock_irqsave(&priv->lock, lock_flags); priv->tdms |= BIT(dai->driver->id); + spin_unlock_irqrestore(&priv->lock, lock_flags); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + spin_lock_irqsave(&priv->lock, lock_flags); priv->tdms &= ~BIT(dai->driver->id); + spin_unlock_irqrestore(&priv->lock, lock_flags); break; default: return -EINVAL; @@ -491,6 +496,7 @@ static int fsl_audmix_probe(struct platform_device *pdev) return PTR_ERR(priv->ipg_clk); } + spin_lock_init(&priv->lock); platform_set_drvdata(pdev, priv); pm_runtime_enable(dev); diff --git a/sound/soc/fsl/fsl_audmix.h b/sound/soc/fsl/fsl_audmix.h index 7812ffec45c5..479f05695d53 100644 --- a/sound/soc/fsl/fsl_audmix.h +++ b/sound/soc/fsl/fsl_audmix.h @@ -96,6 +96,7 @@ struct fsl_audmix { struct platform_device *pdev; struct regmap *regmap; struct clk *ipg_clk; + spinlock_t lock; /* Protect tdms */ u8 tdms; }; -- 2.21.0