From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0691369236 for ; Sun, 10 May 2026 08:44:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778402644; cv=none; b=qlV+HbbXdF3XSCHk+BlnO/M+CzYE3m9VWC38UCXHvjUS7VyXaHivVq1S7QgFXPCvTp38+OxvvgxkUhSlNlRCQPplW2UdNfzhljwaIc92zL/esFqIjO9XDanc/1RsBe20y2qBc0UInKU/VKsR8aGElQFRebFNA5iiPFHWAN9/6Ak= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778402644; c=relaxed/simple; bh=EzZNAd1+G2Bcw6lQD7STgANBRJQkZJfEQMfEQAU1dt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TZzpFioqbHUUaOh5Ul9Fr5hKy4HjkGD+0aUA+4lTjnZmpF0AZe8GiKzcZS3+ydIL+iqYH7fbmO2xg1SRdLzfns5Xs5YbScljjt7uNMiSc49bv+zp5JPh845J/kUNXzZumRzs9JKNYHYcmmiqRLEtBvhfrHR67hn92tas7z+Q+Mo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hGUQhczD; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hGUQhczD" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2b9fcf7c91bso32773565ad.0 for ; Sun, 10 May 2026 01:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778402642; x=1779007442; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YoAF9ct07fH3np99W6VPHFamBb7fo7xQbBMbY6jH4Mc=; b=hGUQhczDNdB7euInoK9CgBYWVVASDyUEHx/ALF4J1Sr2NcFxx6Y5tiZpLX5VLCBY3u QeCDZ6J69s5dF//WP48k/9ykj1TtdoGzo2iEYqckRP6XhVYoiYhWaGdxo2T98kp0Q0qn o1l077q5C2EGgVDWoitt10UxEsW+NOeo1wwLvI69wO8Su/jS2BnnPHpTzOHopvYI4Dt2 9eWhDzR+EKsgGX8Y3CPQEu9bcnMoO4APUyTGsUvTc3J7NNa2823DoeNpq4oR0fq08i/c R/9R/uo1E8DToDWkCXrdmkisPlh95f0YweVuwCj+PGJGwvorQ2l+65Dh4uxz15fCWtEd cdZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778402642; x=1779007442; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=YoAF9ct07fH3np99W6VPHFamBb7fo7xQbBMbY6jH4Mc=; b=TBRjwm3uqlnFDhgsC62Kks699ov9y3raUE4cIB8ubayMO2eQYllFSbv7+/u/7kf826 12k1v99/8t2vro/1GqhEyK1K7SSD40HQJa8n5+WfPqIRW7Df154EtKbStu7okDbcJdVI IBvXWSMrXs1nWBSMCafWQlz1xUDE3fDz+aalEhpt3UL7ZrGunULm05qVtvq6J116AE++ 4TGzAPbC7lnXquxNosCb/d6vtW+V0ta3PlASe23j+N56ILqzmN2FhIBB1U6WF88Vb9+j M5zucP/FqYIGimtyufDcLRe1hbvuPcrMSJjCmMVXlZgoqKD7AaWotyUkPRg+SXECAVAS YlQg== X-Forwarded-Encrypted: i=1; AFNElJ//SD50hbNM2FDit4mf/O2Y70fFPHXjBqKxcxPco/BizZAgZsQM8wZixtNMsomv1ef8dc2kL1aWvO3W@vger.kernel.org X-Gm-Message-State: AOJu0Yw2udiZ4FrFggHvxQR8SklQFEUCoyu3qcAwaPotMNP1K2GyNXZ1 1rPIkZ6FkiJK7tTPUjPnS8dDiogybOMr6gfH+ILsk2o6Zs1X3XypgMfZ X-Gm-Gg: Acq92OFfKTm3C8TjylJR+DnMOhlgXNS+NuXyq5pfXhaMjd+T+0/9+crs5HTKjfre/hX uX5XrFAw8G0ChsbjoIvtn7dVvAE+vik+MC8dPwshJuxDmNb6Ak+QAFwVf8lHxtiZ99TguJmjpXR lXNhVvlX5bJQK5TrppnOU4IgmTSzwGjlMF3rbMp/97xRYsEGNB+/go17CZ1253A6VlvQhDIS0zB gnhVZBWnfqhKH0BhrgDuFbf0TMqZItomcYbPkUeUNn9UdF9BQrapJvZ6LwVfY2XkvJ8DyUMYR8l WgGmu3HVN59XJmGAgpWYEyJB0/wZ7xRF9zm8A4jEU+QdbymMYDKhA6fWcKWEggtG8GRngipC48m G+jCc/stILkVZ4JOP9LWqJZRnM6ovEZLfMPHUjsG8VttllT5gaH6FeywV4hkBgvFrrKA4Bpiph5 VMwuC8F0uDVTMO9Kw+SpktKFP8PKjjFPevmwaXilXutgAcea2E195iRCUrTg== X-Received: by 2002:a17:902:8641:b0:2ba:6ffa:bde0 with SMTP id d9443c01a7336-2ba79c20bb9mr157009065ad.19.1778402642292; Sun, 10 May 2026 01:44:02 -0700 (PDT) Received: from phuc-desktop.. ([183.91.15.56]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d3ffa0sm70471005ad.25.2026.05.10.01.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2026 01:44:02 -0700 (PDT) From: phucduc.bui@gmail.com To: kuninori.morimoto.gx@renesas.com Cc: broonie@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, geert+renesas@glider.be, krzk+dt@kernel.org, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-sound@vger.kernel.org, magnus.damm@gmail.com, perex@perex.cz, robh@kernel.org, tiwai@suse.com, bui duc phuc Subject: [PATCH v3 04/10] ASoC: renesas: fsi: Fix register access from in-flight IRQ after shutdown Date: Sun, 10 May 2026 15:42:57 +0700 Message-ID: <20260510084303.122426-5-phucduc.bui@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260510084303.122426-1-phucduc.bui@gmail.com> References: <20260510084303.122426-1-phucduc.bui@gmail.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: bui duc phuc Ensure that in-flight IRQ handlers do not access hardware registers after SNDRV_PCM_TRIGGER_STOP and fsi_hw_shutdown(). An IRQ handler may still be running when the SPU clock is disabled, leading to register access after clock shutdown and causing system hangs. Prevent register access in the IRQ path once the hardware has been shut down. Signed-off-by: bui duc phuc --- sound/soc/renesas/fsi.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/sound/soc/renesas/fsi.c b/sound/soc/renesas/fsi.c index 94ab2e490810..fc8428cb1ba7 100644 --- a/sound/soc/renesas/fsi.c +++ b/sound/soc/renesas/fsi.c @@ -211,6 +211,7 @@ struct fsi_stream { int sample_width; /* sample width */ int uerr_num; int oerr_num; + bool running; /* * bus options @@ -255,6 +256,8 @@ struct fsi_priv { u32 fmt; + int running_streams; + int chan_num:16; unsigned int clk_master:1; unsigned int clk_cpg:1; @@ -460,6 +463,9 @@ static int fsi_get_current_fifo_samples(struct fsi_priv *fsi, static void fsi_count_fifo_err(struct fsi_priv *fsi) { + if (fsi->running_streams == 0) + return; + u32 ostatus = fsi_reg_read(fsi, DOFF_ST); u32 istatus = fsi_reg_read(fsi, DIFF_ST); @@ -681,6 +687,9 @@ static void fsi_irq_clear_status(struct fsi_priv *fsi) u32 data = 0; struct fsi_master *master = fsi_get_master(fsi); + if (fsi->running_streams == 0) + return; + data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->playback)); data |= AB_IO(1, fsi_get_port_shift(fsi, &fsi->capture)); @@ -1573,10 +1582,17 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, { struct fsi_priv *fsi = fsi_get_priv(substream); struct fsi_stream *io = fsi_stream_get(fsi, substream); + bool need_shutdown = false; int ret = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: + scoped_guard(spinlock_irqsave, &fsi->master->lock) { + if (!io->running) { + io->running = true; + fsi->running_streams++; + } + } fsi_stream_init(fsi, io, substream); if (!ret) ret = fsi_hw_startup(fsi, io, dai->dev); @@ -1586,8 +1602,15 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, ret = fsi_stream_transfer(io); break; case SNDRV_PCM_TRIGGER_STOP: + scoped_guard(spinlock_irqsave, &fsi->master->lock) { + if (io->running) { + io->running = false; + if (--fsi->running_streams == 0) + need_shutdown = true; + } + } fsi_stream_stop(fsi, io); - if (!ret) + if (!ret && need_shutdown) ret = fsi_hw_shutdown(fsi, dai->dev); fsi_stream_quit(fsi, io); break; @@ -1968,6 +1991,7 @@ static int fsi_probe(struct platform_device *pdev) fsi->base = master->base; fsi->phys = res->start; fsi->master = master; + fsi->running_streams = 0; fsi_port_info_init(fsi, &info.port_a); fsi_handler_init(fsi, &info.port_a); ret = fsi_stream_probe(fsi, &pdev->dev); @@ -1981,6 +2005,7 @@ static int fsi_probe(struct platform_device *pdev) fsi->base = master->base + 0x40; fsi->phys = res->start + 0x40; fsi->master = master; + fsi->running_streams = 0; fsi_port_info_init(fsi, &info.port_b); fsi_handler_init(fsi, &info.port_b); ret = fsi_stream_probe(fsi, &pdev->dev); -- 2.43.0