From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 C798335E953 for ; Sun, 10 May 2026 08:44:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778402644; cv=none; b=QS6HUGLCy1NKA7cq/O+ukH0vJ6ZG67R9pD8pHxlW4DyNdK1aBEFYsw+sj/zbozI5Mz7S0rGMu1tz7MDQVMM62IAVbe3cAheE6GwLCJF7QEZnL44IyafNB60dtUpGJo6AKNVNPFgcPFztF1OPTRKCUCzqeP12yzE+Vg6BsNtiNKc= 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.174 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-f174.google.com with SMTP id d9443c01a7336-2bc78d56d3aso6869725ad.2 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=fBPQAbKKySav/kLpML25QVnd0YLbmxPiuZzvfy9BrGVsNPITAHLskM5NFKS95aQJ6U N0o5MV/Oy4if+D68XEtcD+u9TLoBV7TrFfhEWOO/598ti5G+zOYHr95OoFGoW6XCx5HQ U3vl3WfDncZouf3z3gE4pbceaQdkXpmoTVjmmODIBozwC9Lgp2iR8aAPcCTgJo0vFLKi VzNMy7NFyPRtljpOrQv7pFdJSDCcLR3tnY0X3zRSew/OnhE1La0C1ErfynUw+vV446ph MW3b4GZx0rYwwt9fYiz2Uf+HJ0r6DEVo58abOb9/OCMoppqWv74v3B9tbg2ePKaCefb8 Yk3w== X-Forwarded-Encrypted: i=1; AFNElJ+zuAYEFfSGdULhfdTVvnKNTVB7xYTShudGXXUoIOQlcQGMZrTlFlbbYBDf7pmGdHr4/NM1/LfjlV3n+Q==@vger.kernel.org X-Gm-Message-State: AOJu0YxPVdkk78giMTbcYkhntMkZmx3nhhFQznZEQcY2w5mqWB3AIsLJ yuXatwqyWyDAxgHSEE7s9u9d/yM1ipcwWHobw1culA3kMX9Qcra1Aflm X-Gm-Gg: Acq92OF8nI/d1hQlJmP+2M1ld9MbEHY/hW3Raj5hGJxeJOwJi8InSIgbnBmNmzWnOJY blzAUPYTPqCvdNR5kkTG3kBBeR/ztzlhIapgdrvRzGpa6ffNuKK2XhuQycx8oW8vXaj+LTVYhX8 r+jkDaWFknRtqMYEFVFMZe/60PJcFxtRN/cgXpoz+0KMRl0JngGQ7jXoJxaUGSBOJvUqY/IqR2m ieJFttL+HBOhWpAkuqiak54/VSqMKTIcZAuHIMIRtElo3ZxTXlX3q/Zp55vn1AuFvAvtVNOvUNL vHFVHoq7lepDgDH/AL0GXsyNT4tf8BTrbFH1CI/s9iLBYd0pV6FGHw8S0O2Q7H5UyULMxa0EwzG TwR610ZSnAvvOKltSQ7GyATaR0NwHW/qFm0oe1Vpqg7s6JsCsQ54Enz6jkwhkQQSK+CR1uXD77V ZLOecpQ/inIKXPKKbbJaFsW2OC1ZKHRabAe5/Bov8/5yxWo7FbgtmkS5hhPw== 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: linux-sound@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