Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4498421pxb; Tue, 25 Jan 2022 11:39:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjdyTqArRUGBTgdY7S/p6Q03sfaZkH9SsDUksEUcsPiHeNZb6g+CQ1BiwSVpyARppIjQIU X-Received: by 2002:a63:6909:: with SMTP id e9mr16223771pgc.240.1643139589218; Tue, 25 Jan 2022 11:39:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643139589; cv=none; d=google.com; s=arc-20160816; b=RiKu9DoDgbq0w479F5QZ0RnXSjBVazGBU+EmJSr9sezkmkbzm4q6IwnhVcUdamc8Tx A9ICYnIgIqp9wu0ifqADQyV/VYmM79f7WJzPUr4si/clns560oR2u8oVoCU57VKFasxx rc3ea1aG+WIM8Zs4Ph3FHl6dVbpBDpd5P+rksX7EJ+DLEmMnucuHhPuBKFG5FM8U7ze3 7FkAIzM6dc/D4jht850J7cnpPQI2Uu74cBefdm6aOAI3+VI3QgiEjzlgRr1lw7Oe4FPm sQ/TCisBoHee6gLO0JewtYbSQZ1oXoR7GUS9dVmgxyDklgiYL2mODgU7dJtnz6VBwMp8 WfNw== 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=EP6B6uGSzMirn319MWeAuXiPDxTsLEW3ElVn3c2xi2Q=; b=j8PWG7leH2+15EaWCF2b27qpvEsXYp2DI09KYRvd36WKGqiybJLaMUwNWeUyB2QX4B HDYeUoYaU+HAZNnkvYxX5p8HnGk7wgJExKXIfdv2EFuBZIFdpZp7H26Dl3OvPDZ3xEVN W19Xg507TE/PwigdGU9BzoZPOrRl94Svyuq+REVU2R7K0H/3ru221ND7LtVxNmlg0jfs 1NiVtt4l6P4taaoRj99vxZ7O6y9+ToBC4CpXi4EsN4LAa567cVaAzV/yryUUe3CaqHwY YkE/bIJW4SU7fh31Nrucj9QdJWIox7WDEJONQkMrA/TAOsq6rvnqN7rdI4luUCT1QU46 RKWA== 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 b13si16531979pfm.244.2022.01.25.11.39.32; Tue, 25 Jan 2022 11:39:49 -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 S1357481AbiAYN3y (ORCPT + 99 others); Tue, 25 Jan 2022 08:29:54 -0500 Received: from relmlor1.renesas.com ([210.160.252.171]:15749 "EHLO relmlie5.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1386682AbiAYNZT (ORCPT ); Tue, 25 Jan 2022 08:25:19 -0500 X-IronPort-AV: E=Sophos;i="5.88,314,1635174000"; d="scan'208";a="107606150" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 25 Jan 2022 22:25:17 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id D6F29429594A; Tue, 25 Jan 2022 22:25:14 +0900 (JST) From: Lad Prabhakar To: Mark Brown , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, Pavel Machek Cc: linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Biju Das , Prabhakar , Lad Prabhakar Subject: [PATCH 2/3] ASoC: sh: rz-ssi: Add rz_ssi_set_substream() helper function Date: Tue, 25 Jan 2022 13:24:56 +0000 Message-Id: <20220125132457.14984-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220125132457.14984-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220125132457.14984-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 --- 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 2c8775d37f50..1a46c9f3c4e5 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