From patchwork Mon Jan 10 09:47:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prabhakar X-Patchwork-Id: 12708545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9323CC433EF for ; Mon, 10 Jan 2022 09:49:51 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B46BE17A4; Mon, 10 Jan 2022 10:48:59 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B46BE17A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1641808189; bh=9sTJXCSWDlEleCoSEdYWDukHIqg4BLDYmPSY+oJ/qd4=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=q7AG/08fHdzJ/hsjXArtC0rCSm4fBz2n4raTJVUBoXRnYEUweQeBrj7fU+Lrn/lX5 hEOaWZMMjnROeeSjQIYI2i7NPYoI9z1s+4IXHVdiNpFkFCVok2DK2toucxN+UXdZnv XYuwif637gT9ZD4lrTlelmKT5Sn74zwhDAPEmSl4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3E392F8050F; Mon, 10 Jan 2022 10:48:15 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B37C7F80125; Mon, 10 Jan 2022 10:48:11 +0100 (CET) Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by alsa1.perex.cz (Postfix) with ESMTP id 6A0C8F80125 for ; Mon, 10 Jan 2022 10:47:55 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6A0C8F80125 X-IronPort-AV: E=Sophos;i="5.88,276,1635174000"; d="scan'208";a="106003021" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 10 Jan 2022 18:47:51 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 1125B4238CA4; Mon, 10 Jan 2022 18:47:48 +0900 (JST) From: Lad Prabhakar To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Lad Prabhakar , Biju Das Subject: [PATCH 1/5] ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively Date: Mon, 10 Jan 2022 09:47:07 +0000 Message-Id: <20220110094711.8574-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Cc: linux-renesas-soc@vger.kernel.org, Pavel Machek , Prabhakar , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Instead of recursively calling rz_ssi_pio_recv() use a while loop to read the samples from RX fifo. This also fixes an issue where the return value of rz_ssi_pio_recv() was ignored when called recursively. Fixes: 03e786bd4341 ("ASoC: sh: Add RZ/G2L SSIF-2 driver") Reported-by: Pavel Machek Signed-off-by: Lad Prabhakar Reviewed-by: Biju Das --- sound/soc/sh/rz-ssi.c | 68 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index fa0cc08f70ec..37466f65c2b0 100644 --- a/sound/soc/sh/rz-ssi.c +++ b/sound/soc/sh/rz-ssi.c @@ -411,54 +411,56 @@ static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) { struct snd_pcm_substream *substream = strm->substream; struct snd_pcm_runtime *runtime; + bool done = false; u16 *buf; int fifo_samples; int frames_left; - int samples = 0; + int samples; int i; if (!rz_ssi_stream_is_valid(ssi, strm)) return -EINVAL; runtime = substream->runtime; - /* frames left in this period */ - frames_left = runtime->period_size - (strm->buffer_pos % - runtime->period_size); - if (frames_left == 0) - frames_left = runtime->period_size; - /* Samples in RX FIFO */ - fifo_samples = (rz_ssi_reg_readl(ssi, SSIFSR) >> - SSIFSR_RDC_SHIFT) & SSIFSR_RDC_MASK; - - /* Only read full frames at a time */ - while (frames_left && (fifo_samples >= runtime->channels)) { - samples += runtime->channels; - fifo_samples -= runtime->channels; - frames_left--; - } + while (!done) { + /* frames left in this period */ + frames_left = runtime->period_size - + (strm->buffer_pos % runtime->period_size); + if (!frames_left) + frames_left = runtime->period_size; + + /* Samples in RX FIFO */ + fifo_samples = (rz_ssi_reg_readl(ssi, SSIFSR) >> + SSIFSR_RDC_SHIFT) & SSIFSR_RDC_MASK; + + /* Only read full frames at a time */ + samples = 0; + while (frames_left && (fifo_samples >= runtime->channels)) { + samples += runtime->channels; + fifo_samples -= runtime->channels; + frames_left--; + } - /* not enough samples yet */ - if (samples == 0) - return 0; + /* not enough samples yet */ + if (!samples) + break; - /* calculate new buffer index */ - buf = (u16 *)(runtime->dma_area); - buf += strm->buffer_pos * runtime->channels; + /* calculate new buffer index */ + buf = (u16 *)(runtime->dma_area); + buf += strm->buffer_pos * runtime->channels; - /* Note, only supports 16-bit samples */ - for (i = 0; i < samples; i++) - *buf++ = (u16)(rz_ssi_reg_readl(ssi, SSIFRDR) >> 16); + /* Note, only supports 16-bit samples */ + for (i = 0; i < samples; i++) + *buf++ = (u16)(rz_ssi_reg_readl(ssi, SSIFRDR) >> 16); - rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); - rz_ssi_pointer_update(strm, samples / runtime->channels); + rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); + rz_ssi_pointer_update(strm, samples / runtime->channels); - /* - * If we finished this period, but there are more samples in - * the RX FIFO, call this function again - */ - if (frames_left == 0 && fifo_samples >= runtime->channels) - rz_ssi_pio_recv(ssi, strm); + /* check if there are no more samples in the RX FIFO */ + if (!(!frames_left && fifo_samples >= runtime->channels)) + done = true; + } return 0; } From patchwork Mon Jan 10 09:47:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prabhakar X-Patchwork-Id: 12708543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B1CCCC433EF for ; Mon, 10 Jan 2022 09:49:01 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 10053170C; Mon, 10 Jan 2022 10:48:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 10053170C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1641808139; bh=g1/VSzPkipKjtgRQx+wrsF9qk7j/Iefxacm6M1Yqe8o=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RwlV5QEZ0o/t48SGNXSr1m9WK9O1oPmFehljmJxyQy7qJYQ+RTLYPNx2L19M30JnM yIU9ICX/bzqIPaSqpPVQ+TFG0zXUoBT9U6SDCNFpOX7h/mhUTNbursvCbyE72eszzc FQt7g75aPwGO6AYRarmTgPs2T8jqwBsUXBP+WfGg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9069AF8025A; Mon, 10 Jan 2022 10:48:08 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B1956F804F2; Mon, 10 Jan 2022 10:48:06 +0100 (CET) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id 2791EF80054 for ; Mon, 10 Jan 2022 10:47:57 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2791EF80054 X-IronPort-AV: E=Sophos;i="5.88,276,1635174000"; d="scan'208";a="106545250" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 10 Jan 2022 18:47:54 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 0EEBE4238CA4; Mon, 10 Jan 2022 18:47:51 +0900 (JST) From: Lad Prabhakar To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Subject: [PATCH 2/5] ASoC: sh: rz-ssi: Make the data structures available before registering the handlers Date: Mon, 10 Jan 2022 09:47:08 +0000 Message-Id: <20220110094711.8574-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Cc: alsa-devel@alsa-project.org, Pavel Machek , Lad Prabhakar , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Initialize the spinlock and make the data structures available before registering the interrupt handlers. Reported-by: Pavel Machek Signed-off-by: Lad Prabhakar Reviewed-by: Biju Das --- sound/soc/sh/rz-ssi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index 37466f65c2b0..16de2633a873 100644 --- a/sound/soc/sh/rz-ssi.c +++ b/sound/soc/sh/rz-ssi.c @@ -977,6 +977,9 @@ static int rz_ssi_probe(struct platform_device *pdev) ssi->playback.priv = ssi; ssi->capture.priv = ssi; + spin_lock_init(&ssi->lock); + dev_set_drvdata(&pdev->dev, ssi); + /* Error Interrupt */ ssi->irq_int = platform_get_irq_byname(pdev, "int_req"); if (ssi->irq_int < 0) @@ -1024,8 +1027,6 @@ static int rz_ssi_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); pm_runtime_resume_and_get(&pdev->dev); - spin_lock_init(&ssi->lock); - dev_set_drvdata(&pdev->dev, ssi); ret = devm_snd_soc_register_component(&pdev->dev, &rz_ssi_soc_component, rz_ssi_soc_dai, ARRAY_SIZE(rz_ssi_soc_dai)); From patchwork Mon Jan 10 09:47:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prabhakar X-Patchwork-Id: 12708544 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35B49C433EF for ; Mon, 10 Jan 2022 09:49:39 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 18DA11798; Mon, 10 Jan 2022 10:48:47 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 18DA11798 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1641808177; bh=OYzp/+MX59Oko0XJJi29+jScJae8cDDkTzIiwwiN93A=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cd/nClc8i9hxBSWWxNhYKH5Qi4LPajpO1zMT05iL8981jjQh0rz5qZ+l4TkTNLA3B 59PYz8lOCJtKjXa7kAd8i2T/o6+T5HQHhJVEE57sm985H67YPZfy+uFEQ4v9hUyRb2 5S5p5R2cP7FGc7jTiUCqS947zngLlq23RUfImwWM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3F648F800B6; Mon, 10 Jan 2022 10:48:10 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C836CF804BC; Mon, 10 Jan 2022 10:48:07 +0100 (CET) Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by alsa1.perex.cz (Postfix) with ESMTP id DF03BF800B6 for ; Mon, 10 Jan 2022 10:47:58 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DF03BF800B6 X-IronPort-AV: E=Sophos;i="5.88,276,1635174000"; d="scan'208";a="106003028" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 10 Jan 2022 18:47:57 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 1380D4238CA4; Mon, 10 Jan 2022 18:47:54 +0900 (JST) From: Lad Prabhakar To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Subject: [PATCH 3/5] ASoC: sh: rz-ssi: Drop ssi parameter from rz_ssi_stream_init() Date: Mon, 10 Jan 2022 09:47:09 +0000 Message-Id: <20220110094711.8574-4-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Cc: alsa-devel@alsa-project.org, Pavel Machek , Lad Prabhakar , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" ssi parameter is unused in rz_ssi_stream_init() so just drop it. While at it, change the return type of rz_ssi_stream_init() to void instead of int. Signed-off-by: Lad Prabhakar Reviewed-by: Biju Das --- sound/soc/sh/rz-ssi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index 16de2633a873..fa68d3a0bd62 100644 --- a/sound/soc/sh/rz-ssi.c +++ b/sound/soc/sh/rz-ssi.c @@ -201,9 +201,8 @@ static int rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi, return ret; } -static int rz_ssi_stream_init(struct rz_ssi_priv *ssi, - struct rz_ssi_stream *strm, - struct snd_pcm_substream *substream) +static void rz_ssi_stream_init(struct rz_ssi_stream *strm, + struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; @@ -219,8 +218,6 @@ static int rz_ssi_stream_init(struct rz_ssi_priv *ssi, /* fifo init */ strm->fifo_sample_size = SSI_FIFO_DEPTH; - - return 0; } static void rz_ssi_stream_quit(struct rz_ssi_priv *ssi, @@ -728,9 +725,7 @@ static int rz_ssi_dai_trigger(struct snd_pcm_substream *substream, int cmd, rz_ssi_reg_mask_setl(ssi, SSIFCR, SSIFCR_SSIRST, 0); udelay(5); - ret = rz_ssi_stream_init(ssi, strm, substream); - if (ret) - goto done; + rz_ssi_stream_init(strm, substream); if (ssi->dma_rt) { bool is_playback; From patchwork Mon Jan 10 09:47:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prabhakar X-Patchwork-Id: 12708546 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8F72C433EF for ; Mon, 10 Jan 2022 09:50:08 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 221B317B3; Mon, 10 Jan 2022 10:49:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 221B317B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1641808207; bh=u0/QazhwAru1ZOtWn7gUMMCW3D667oKJgPNfXlFHklE=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ugmntAdpItbdruX7jxyaz9xB6eJOVpUQSy4RGoPWUyyeZJ12iwq70dkxICpvpjh+d ifwKsaQ/SfftfdjWvumhuIN5ksuajRJbwhL8EOfvPcqF240zyXQ/f88RDhSSudU1A7 5pmwCVl+UQl7JFYWmSy4KznEuW8fZKICWG40aizU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C1CDBF80248; Mon, 10 Jan 2022 10:48:48 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 35925F80518; Mon, 10 Jan 2022 10:48:47 +0100 (CET) Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by alsa1.perex.cz (Postfix) with ESMTP id E881CF80134 for ; Mon, 10 Jan 2022 10:48:02 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E881CF80134 X-IronPort-AV: E=Sophos;i="5.88,276,1635174000"; d="scan'208";a="106003032" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 10 Jan 2022 18:48:00 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 160774238CA4; Mon, 10 Jan 2022 18:47:57 +0900 (JST) From: Lad Prabhakar To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Subject: [PATCH 4/5] ASoC: sh: rz-ssi: Make return type of rz_ssi_stream_is_valid() to bool Date: Mon, 10 Jan 2022 09:47:10 +0000 Message-Id: <20220110094711.8574-5-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Cc: alsa-devel@alsa-project.org, Pavel Machek , Lad Prabhakar , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" rz_ssi_stream_is_valid() never returns an int, it returns the result of a condition which is either true or false. While at it, drop "!!" as the expression is boolean. Reported-by: Pavel Machek Signed-off-by: Lad Prabhakar Reviewed-by: Biju Das --- sound/soc/sh/rz-ssi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index fa68d3a0bd62..aabd15e9d515 100644 --- a/sound/soc/sh/rz-ssi.c +++ b/sound/soc/sh/rz-ssi.c @@ -188,14 +188,14 @@ 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 int rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi, - struct rz_ssi_stream *strm) +static bool rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi, + struct rz_ssi_stream *strm) { unsigned long flags; - int ret; + bool ret; spin_lock_irqsave(&ssi->lock, flags); - ret = !!(strm->substream && strm->substream->runtime); + ret = strm->substream && strm->substream->runtime; spin_unlock_irqrestore(&ssi->lock, flags); return ret; From patchwork Mon Jan 10 09:47:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Prabhakar X-Patchwork-Id: 12708547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48D4FC433EF for ; Mon, 10 Jan 2022 09:50:43 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 6E34117E0; Mon, 10 Jan 2022 10:49:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6E34117E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1641808241; bh=dn8pmcGSz/09RA9zuzSxTWyhiebMQ9U2OjT8AtUfbdU=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=epnnWyfdykuUn5dKPhyzMBJRE+5ktACMavXi8M09Q2EBf4bgI1kz/8nY+NU3X34b8 R3cpfp9AWUjjCX5tSEf2MZTz9sg7Ez09FN3DApQ1oldd47vjaWQeTFkKCoQiQnMtP4 b+CvaWJmoLTJLbwLxGLYC4u0HQYEkYA0uDb4a6JM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id DBA34F8051A; Mon, 10 Jan 2022 10:48:49 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 396B9F8012E; Mon, 10 Jan 2022 10:48:47 +0100 (CET) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id B44C5F80248 for ; Mon, 10 Jan 2022 10:48:03 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B44C5F80248 X-IronPort-AV: E=Sophos;i="5.88,276,1635174000"; d="scan'208";a="106545264" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 10 Jan 2022 18:48:03 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 1D68C4238CA4; Mon, 10 Jan 2022 18:48:00 +0900 (JST) From: Lad Prabhakar To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Subject: [PATCH 5/5] ASoC: sh: rz-ssi: Add functions to get/set substream pointer Date: Mon, 10 Jan 2022 09:47:11 +0000 Message-Id: <20220110094711.8574-6-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220110094711.8574-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Pavel Machek , Lad Prabhakar , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 and in rest of the driver no locking was used while assigning substream pointer. This patch adds functions to get/set substream pointer with locks acquired and replaces the instances of access to substream pointer with the get/set functions. Reported-by: Pavel Machek Signed-off-by: Lad Prabhakar Reviewed-by: Biju Das --- sound/soc/sh/rz-ssi.c | 55 ++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index aabd15e9d515..057aedacedec 100644 --- a/sound/soc/sh/rz-ssi.c +++ b/sound/soc/sh/rz-ssi.c @@ -201,12 +201,36 @@ static bool rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi, return ret; } +static struct snd_pcm_substream *rz_ssi_get_substream(struct rz_ssi_stream *strm) +{ + struct rz_ssi_priv *ssi = strm->priv; + struct snd_pcm_substream *substream; + unsigned long flags; + + spin_lock_irqsave(&ssi->lock, flags); + substream = strm->substream; + spin_unlock_irqrestore(&ssi->lock, flags); + + return substream; +} + +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 void rz_ssi_stream_init(struct rz_ssi_stream *strm, struct snd_pcm_substream *substream) { 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; @@ -223,12 +247,13 @@ static void rz_ssi_stream_init(struct rz_ssi_stream *strm, 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; + struct snd_pcm_substream *substream; + struct snd_soc_dai *dai; - spin_lock_irqsave(&ssi->lock, flags); - strm->substream = NULL; - spin_unlock_irqrestore(&ssi->lock, flags); + substream = rz_ssi_get_substream(strm); + rz_ssi_set_substream(strm, NULL); + + dai = rz_ssi_get_dai(substream); if (strm->oerr_num > 0) dev_info(dai->dev, "overrun = %d\n", strm->oerr_num); @@ -301,7 +326,8 @@ static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, unsigned int rate, static int rz_ssi_start(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) { - bool is_play = rz_ssi_stream_is_play(ssi, strm->substream); + struct snd_pcm_substream *substream = rz_ssi_get_substream(strm); + bool is_play = rz_ssi_stream_is_play(ssi, substream); u32 ssicr, ssifcr; ssicr = rz_ssi_reg_readl(ssi, SSICR); @@ -382,7 +408,7 @@ static int rz_ssi_stop(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) static void rz_ssi_pointer_update(struct rz_ssi_stream *strm, int frames) { - struct snd_pcm_substream *substream = strm->substream; + struct snd_pcm_substream *substream = rz_ssi_get_substream(strm); struct snd_pcm_runtime *runtime; int current_period; @@ -399,14 +425,14 @@ static void rz_ssi_pointer_update(struct rz_ssi_stream *strm, int frames) current_period = strm->buffer_pos / runtime->period_size; if (strm->period_counter != current_period) { - snd_pcm_period_elapsed(strm->substream); + snd_pcm_period_elapsed(substream); strm->period_counter = current_period; } } static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) { - struct snd_pcm_substream *substream = strm->substream; + struct snd_pcm_substream *substream = rz_ssi_get_substream(strm); struct snd_pcm_runtime *runtime; bool done = false; u16 *buf; @@ -464,7 +490,7 @@ static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) static int rz_ssi_pio_send(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) { - struct snd_pcm_substream *substream = strm->substream; + struct snd_pcm_substream *substream = rz_ssi_get_substream(strm); struct snd_pcm_runtime *runtime = substream->runtime; int sample_space; int samples = 0; @@ -588,7 +614,7 @@ static int rz_ssi_dma_slave_config(struct rz_ssi_priv *ssi, static int rz_ssi_dma_transfer(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) { - struct snd_pcm_substream *substream = strm->substream; + struct snd_pcm_substream *substream = rz_ssi_get_substream(strm); struct dma_async_tx_descriptor *desc; struct snd_pcm_runtime *runtime; enum dma_transfer_direction dir; @@ -646,12 +672,13 @@ static int rz_ssi_dma_transfer(struct rz_ssi_priv *ssi, static void rz_ssi_dma_complete(void *data) { struct rz_ssi_stream *strm = (struct rz_ssi_stream *)data; + struct snd_pcm_substream *substream = rz_ssi_get_substream(strm); - if (!strm->running || !strm->substream || !strm->substream->runtime) + if (!strm->running || !substream || !substream->runtime) return; /* Note that next DMA transaction has probably already started */ - rz_ssi_pointer_update(strm, strm->substream->runtime->period_size); + rz_ssi_pointer_update(strm, substream->runtime->period_size); /* Queue up another DMA transaction */ rz_ssi_dma_transfer(strm->priv, strm);