Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1268044pxb; Sat, 15 Jan 2022 07:24:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9AVO4El8WKXMlqo5HozTTB33vkYsKfsgu4rUgbwzfxbmJTaesa1UPExeOkwh7yOcRSjX6 X-Received: by 2002:a17:907:6287:: with SMTP id nd7mr10760468ejc.152.1642260295900; Sat, 15 Jan 2022 07:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642260295; cv=none; d=google.com; s=arc-20160816; b=PT3Dd0mjaF2yXY2xx+ulriWiUPNJhO1bT+KAjNMq7Rrt89SPpD1aCDbigBI/JDJ/bK 75iu537cJ9tyF/3J3tL1tFWmzYEAxpGiEOhdztVIuPPZse8cdFPWn494dqQW/UOe+AE+ vbNSRCclZiTMafLD5/tC98c3bt4myeSwSAJFd37zhOWXeM+KLvJrk3JksM0q4xQaOjWN 74S56FVrzL9PuohEQ/FJflT88WXewRaNvYJc2IUiLU4V44drZn/5z+UMAqPz+tirtjMs fdEeAiw5U/SCN+pWYz2Rgt5IYNODSNe1xAeZKFuoPIHj+S93cTY+WcMhPdE86AS/zqm4 u1/Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+TgpMWgaQFPnSx8rx4dfQm/yoLeImGVzYtDY+SiMRGY=; b=a8MSbSY+sl021FMcZWEVrLyH7dXfH9cs9x/TQV5hkuHL6Ro23UDgkDeDGvnvgVm3vX DwL4ayy2wMTJSXqJzz7Yqe5N0i8vzUdVmCUNrrB/MUnNqjGn7s0roypSOyexH8b70Yco m66/h26y5ebmo6wvcV9YCux+A/Jyn3wyacSwFU0vrv0poUBNEi1Fly+HiYQVDZVj7sR9 87Gilze2HZ7k1MnwBJUwbJmaRAWuE2ncTGggCF1h5lRTmbY9WB0QlZVBE1tuGBhT85Cz 9Qhq85UA0nRmWKbgr9fa0aVdKNeSywrL83OnrXl6GgLH7klyUKndsMW1Zz7Pr3L1B8/Y tsVw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id js14si2803250ejc.635.2022.01.15.07.24.31; Sat, 15 Jan 2022 07:24:55 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231968AbiAOBXd (ORCPT + 99 others); Fri, 14 Jan 2022 20:23:33 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:25388 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231989AbiAOBXb (ORCPT ); Fri, 14 Jan 2022 20:23:31 -0500 X-IronPort-AV: E=Sophos;i="5.88,290,1635174000"; d="scan'208";a="107116855" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 15 Jan 2022 10:23:30 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 6473D417EAC4; Sat, 15 Jan 2022 10:23:28 +0900 (JST) From: Lad Prabhakar To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Biju Das , Pavel Machek , Cezary Rojewski , linux-renesas-soc@vger.kernel.org, Prabhakar , Lad Prabhakar , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] ASoC: sh: rz-ssi: Add rz_ssi_set_substream() helper function Date: Sat, 15 Jan 2022 01:23:03 +0000 Message-Id: <20220115012303.29651-6-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220115012303.29651-1-prabhakar.mahadev-lad.rj@bp.renesas.com> 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 A copy of substream pointer is stored in priv structure during rz_ssi_dai_trigger() callback ie in SNDRV_PCM_TRIGGER_START case and the pointer is assigned to NULL in case of SNDRV_PCM_TRIGGER_STOP. The driver used the locks only in rz_ssi_stream_is_valid() and assigned the local substream pointer to NULL in rz_ssi_dai_trigger() callback but never locked it while making a local copy. This patch adds the rz_ssi_set_substream() helper function to set the substream pointer with locks acquired and replaces the instances of setting the local substream pointer with the rz_ssi_set_substream() function. Reported-by: Pavel Machek Signed-off-by: Lad Prabhakar Reviewed-by: Biju Das --- v1->v2 * Dropped rz_ssi_get_substream() helper. --- sound/soc/sh/rz-ssi.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index 2da43eecfb3e..07fdbcfa5b63 100644 --- a/sound/soc/sh/rz-ssi.c +++ b/sound/soc/sh/rz-ssi.c @@ -188,6 +188,17 @@ static inline bool rz_ssi_is_dma_enabled(struct rz_ssi_priv *ssi) return (ssi->playback.dma_ch && (ssi->dma_rt || ssi->capture.dma_ch)); } +static void rz_ssi_set_substream(struct rz_ssi_stream *strm, + struct snd_pcm_substream *substream) +{ + struct rz_ssi_priv *ssi = strm->priv; + unsigned long flags; + + spin_lock_irqsave(&ssi->lock, flags); + strm->substream = substream; + spin_unlock_irqrestore(&ssi->lock, flags); +} + static bool rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) { @@ -206,7 +217,7 @@ static void rz_ssi_stream_init(struct rz_ssi_stream *strm, { struct snd_pcm_runtime *runtime = substream->runtime; - strm->substream = substream; + rz_ssi_set_substream(strm, substream); strm->sample_width = samples_to_bytes(runtime, 1); strm->dma_buffer_pos = 0; strm->period_counter = 0; @@ -224,11 +235,8 @@ static void rz_ssi_stream_quit(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) { struct snd_soc_dai *dai = rz_ssi_get_dai(strm->substream); - unsigned long flags; - spin_lock_irqsave(&ssi->lock, flags); - strm->substream = NULL; - spin_unlock_irqrestore(&ssi->lock, flags); + rz_ssi_set_substream(strm, NULL); if (strm->oerr_num > 0) dev_info(dai->dev, "overrun = %d\n", strm->oerr_num); -- 2.17.1