From patchwork Wed Nov 6 07:27:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 178625 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp416924ocf; Tue, 5 Nov 2019 23:29:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyfwy/zK++9zgRn3knuSG25h1RGxJGqz8ju2bE8Zk2xHJXSVXEoiOGoPWQd3TuvKb+0gc7J X-Received: by 2002:a50:88a6:: with SMTP id d35mr1094788edd.111.1573025367584; Tue, 05 Nov 2019 23:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573025367; cv=none; d=google.com; s=arc-20160816; b=LaB7n81zKrSybY5ZIJJJc741zIMY2SZdhwKpesg18mXi6jRGAp5MtYfyPRYZ99Bd2H z1skBfzwHtpbVQR/Fwx9vBxcMeTaS18CwRXk8g1Uhcnp71/cN4h4zIX2NHKuhurlmx9d uWVyO/7dqZJ1QQ6hTeSHWiUVkNswGCW/XVDxw811umMripe5/+YnKQ44v0Wre9FCrDsu 9EeSxym7IdCw0EhkVFlIRhM2qsNzYr+GDCAcwXcCN9fynj4lTFm+Kkc4MzMVuFnmkL4I 4V9CRb8qf0mVxDP6P299ibO92MVufVXBkSmpQE09lSwfdLoR3euImghZfBXh9ft5exaK 8ePA== 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 ks2si13782423ejb.396.2019.11.05.23.29.27; Tue, 05 Nov 2019 23:29:27 -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 S1731364AbfKFH3Y (ORCPT + 26 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(+) -- 2.21.0 Acked-by: Nicolin Chen 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; };