All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@denx.de>
To: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Cc: cip-dev@lists.cip-project.org,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>,
	Pavel Machek <pavel@denx.de>,
	Biju Das <biju.das.jz@bp.renesas.com>
Subject: Re: [PATCH 5.10.y-cip 03/31] ASoC: sh: Add RZ/G2L SSIF-2 driver
Date: Thu, 30 Dec 2021 12:15:00 +0100	[thread overview]
Message-ID: <20211230111500.GD9799@amd> (raw)
In-Reply-To: <20211229101530.22783-4-prabhakar.mahadev-lad.rj@bp.renesas.com>

[-- Attachment #1: Type: text/plain, Size: 5184 bytes --]

Hi!

> From: Biju Das <biju.das.jz@bp.renesas.com>
> 
> commit 03e786bd43410fa93e5d2459f7a43e90ff0ae801 upstream.
> 
> Add serial sound interface(SSIF-2) driver support for
> RZ/G2L SoC.
> 
> Based on the work done by Chris Brandt for RZ/A SSI driver.

I'm not sure what the locking rules are here.

> --- /dev/null
> +++ b/sound/soc/sh/rz-ssi.c
> +static int rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi,
> +				  struct rz_ssi_stream *strm)
> +{
> +	unsigned long flags;
> +	int ret;
> +
> +	spin_lock_irqsave(&ssi->lock, flags);
> +	ret = !!(strm->substream && strm->substream->runtime);
> +	spin_unlock_irqrestore(&ssi->lock, flags);
> +
> +	return ret;
> +}

Nit: I don't think !!() is useful here, as it is boolean expression
anyway.

But I notice that code is very careful to access strm->substream with
spinlock held.

> +static void rz_ssi_pointer_update(struct rz_ssi_stream *strm, int frames)
> +{
> +	struct snd_pcm_substream *substream = strm->substream;
> +	struct snd_pcm_runtime *runtime;
> +	int current_period;
> +
> +	if (!strm->running || !substream || !substream->runtime)
> +		return;

But here we do same checks, and this time without the spinlock?

> +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;
> +	u16 *buf;
> +	int fifo_samples;
> +	int frames_left;
> +	int samples = 0;
> +	int i;
> +
> +	if (!rz_ssi_stream_is_valid(ssi, strm))
> +		return -EINVAL;
> +
> +	runtime = substream->runtime;

Again, access without locking. 

> +	/*
> +	 * 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);

Here we call ourselves recurively. Without checking the return
value.. but more importantly recursion is unwelcome in kernel due to
limited stack use.


> +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_runtime *runtime = substream->runtime;
> +	int sample_space;
> +	int samples = 0;
> +	int frames_left;
> +	int i;
> +	u32 ssifsr;
> +	u16 *buf;
> +
> +	if (!rz_ssi_stream_is_valid(ssi, strm))
> +		return -EINVAL;

Access without locking before verifying that stream is valid with the
lock. This is wrong. 

> +static irqreturn_t rz_ssi_interrupt(int irq, void *data)
> +{
> +	struct rz_ssi_stream *strm = NULL;
> +	struct rz_ssi_priv *ssi = data;
> +	u32 ssisr = rz_ssi_reg_readl(ssi, SSISR);
> +
> +	if (ssi->playback.substream)
> +		strm = &ssi->playback;
> +	else if (ssi->capture.substream)
> +		strm = &ssi->capture;
> +	else
> +		return IRQ_HANDLED; /* Left over TX/RX interrupt */

You mark interrupt as handled even when it is not. Probably not a
problem w/o shared interrupts.

> +static int rz_ssi_probe(struct platform_device *pdev)
> +{
...
> +	/* Error Interrupt */
> +	ssi->irq_int = platform_get_irq_byname(pdev, "int_req");
> +	if (ssi->irq_int < 0)
> +		return dev_err_probe(&pdev->dev, -ENODEV,
> +				     "Unable to get SSI int_req IRQ\n");
> +
> +	ret = devm_request_irq(&pdev->dev, ssi->irq_int, &rz_ssi_interrupt,
> +			       0, dev_name(&pdev->dev), ssi);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "irq request error (int_req)\n");
> +
> +	/* Tx and Rx interrupts (pio only) */
> +	ssi->irq_tx = platform_get_irq_byname(pdev, "dma_tx");
> +	if (ssi->irq_tx < 0)
> +		return dev_err_probe(&pdev->dev, -ENODEV,
> +				     "Unable to get SSI dma_tx IRQ\n");
...

So you registered interrupt handlers...

> +
> +	ret = devm_request_irq(&pdev->dev, ssi->irq_tx, &rz_ssi_interrupt, 0,
> +			       dev_name(&pdev->dev), ssi);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "irq request error (dma_tx)\n");
> +
> +	ssi->irq_rx = platform_get_irq_byname(pdev, "dma_rx");
> +	if (ssi->irq_rx < 0)
> +		return dev_err_probe(&pdev->dev, -ENODEV,
> +				     "Unable to get SSI dma_rx IRQ\n");
> +
> +	ret = devm_request_irq(&pdev->dev, ssi->irq_rx, &rz_ssi_interrupt, 0,
> +			       dev_name(&pdev->dev), ssi);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "irq request error (dma_rx)\n");
> +
> +	ssi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
> +	if (IS_ERR(ssi->rstc))
> +		return PTR_ERR(ssi->rstc);
> +
> +	reset_control_deassert(ssi->rstc);
> +	pm_runtime_enable(&pdev->dev);
> +	pm_runtime_resume_and_get(&pdev->dev);
> +
> +	spin_lock_init(&ssi->lock);
> +	dev_set_drvdata(&pdev->dev, ssi);

But only here you have data structures ready to handle the
interrupts. You won't see obvious problems w/o shared interrupts, but
I believe there are debugging modes that trigger this intentionally.

Best regards,
								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2021-12-30 11:15 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-29 10:14 [PATCH 5.10.y-cip 00/31] Add sound/adc support for RZ/G2L Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 01/31] ASoC: dt-bindings: Document RZ/G2L bindings Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 02/31] ASoC: dt-bindings: sound: renesas,rz-ssi: Document DMA support Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 03/31] ASoC: sh: Add RZ/G2L SSIF-2 driver Lad Prabhakar
2021-12-30 11:15   ` Pavel Machek [this message]
2021-12-30 14:18     ` Prabhakar Mahadev Lad
2021-12-30 20:07       ` Pavel Machek
2021-12-29 10:15 ` [PATCH 5.10.y-cip 04/31] ASoC: dt-bindings: renesas,rz-ssi: Update slave dma channel configuration parameter Lad Prabhakar
2021-12-30 10:55   ` Pavel Machek
2021-12-30 13:36     ` Prabhakar Mahadev Lad
2022-01-04 10:25     ` Biju Das
2021-12-29 10:15 ` [PATCH 5.10.y-cip 05/31] ASoC: sh: rz-ssi: Add SSI DMAC support Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 06/31] ASoC: sh: rz-ssi: Fix dereference of noderef expression warning Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 07/31] ASoC: sh: rz-ssi: Fix wrong operator used issue Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 08/31] ASoC: sh: rz-ssi: Improve error handling in rz_ssi_dma_request function Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 09/31] dt-bindings: iio: adc: Add binding documentation for Renesas RZ/G2L A/D converter Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 10/31] iio: adc: Add driver " Lad Prabhakar
2021-12-30 11:00   ` Pavel Machek
2021-12-30 13:39     ` Prabhakar Mahadev Lad
2021-12-29 10:15 ` [PATCH 5.10.y-cip 11/31] iio: adc: rzg2l_adc: Fix -EBUSY timeout error return Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 12/31] iio: adc: rzg2l_adc: add missing clk_disable_unprepare() in rzg2l_adc_pm_runtime_resume() Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 13/31] clk: renesas: r9a07g044: Add SSIF-2 clock and reset entries Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 14/31] clk: renesas: r9a07g044: Add clock and reset entries for ADC Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 15/31] arm64: dts: renesas: r9a07g044: Add ADC node Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 16/31] arm64: dts: renesas: r9a07g044: Add external audio clock nodes Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 17/31] arm64: dts: renesas: r9a07g044: Add SSI support Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 18/31] arm64: dts: renesas: r9a07g044: Add DMA support to SSI Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 19/31] arm64: dts: renesas: rzg2l-smarc: Enable I2C{0,1,3} support Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 20/31] arm64: dts: renesas: rzg2l-smarc: Add WM8978 sound codec Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 21/31] arm64: dts: renesas: rzg2l-smarc: Enable audio Lad Prabhakar
2021-12-30 11:02   ` Pavel Machek
2021-12-30 13:40     ` Prabhakar Mahadev Lad
2021-12-29 10:15 ` [PATCH 5.10.y-cip 22/31] arm64: dts: renesas: rzg2l-smarc: Add Mic routing Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 23/31] arm64: dts: renesas: rzg2l-smarc-som: Move extal and memory nodes to SOM DTSI Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 24/31] arm64: dts: renesas: rzg2l-smarc-som: Enable ADC on SMARC platform Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 25/31] arm64: dts: renesas: rzg2l-smarc: Enable CANFD Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 26/31] arm64: defconfig: Enable SOUND_SOC_RZ Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 27/31] arm64: defconfig: Enable SND_SOC_WM8978 Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 28/31] arm64: defconfig: Enable RZG2L_ADC Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 29/31] clk: renesas: r9a07g044: Mark IA55_CLK and DMAC_ACLK critical Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 30/31] i2c: riic: Add RZ/G2L support Lad Prabhakar
2021-12-29 10:15 ` [PATCH 5.10.y-cip 31/31] arm64: defconfig: Enable RIIC Lad Prabhakar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211230111500.GD9799@amd \
    --to=pavel@denx.de \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.