From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 039B729346F; Sun, 1 Jun 2025 23:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748820765; cv=none; b=la9kI4TE/IkkQBr1vtxxeBQqKipPa1O5TnpEYN4D7mAfb/Ifp6zONeqfYxZdnPwQrS5W4DzA0XzP5ZhitvouAbr5tNn3QFjdTuvG0ivqXhT/ncmYW5Fpi7U3smP9vGH3DVdXIBWNp6wE/XJt5QoSwwRgMOKvbvGqUlgCx+1np6g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748820765; c=relaxed/simple; bh=A48W80d/OvYkJUwQnKQg9w4xhc8rbidgZOgmvwELG1g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=RGviQUpoiaLyw7JGgX6ybklhVzeXqKgckh+DGpTJKb9LfCUJN4WWYsBj47CFQvOJrKrDpV9DXE68DQC31pl08OD0F7tDLYSwxuelE9DyRQOjUGePfIjG6gXXwk/c63WSQqhjGsg7yE7rMcDYEweSqqC4vtclK1QkspdO3G3TXM4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EumRcRvS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EumRcRvS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90E8CC4CEF2; Sun, 1 Jun 2025 23:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748820764; bh=A48W80d/OvYkJUwQnKQg9w4xhc8rbidgZOgmvwELG1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EumRcRvSwmMahgx2lYUYANvzygCuIBqMyjODWh1HRJKjaQS+o56IsNbm1DxHp27f+ MSLTuirU58VmaGQQqisDZ0RHU5ZcB1+Gq6JndK0a1/L+ic0jdtfCdB0C6Z7/RmQTId jiHL+NbNA47IFMDncU6jTCnF8AbFOcbNquVwgn13f8FB4jLtT1GJYaFFD9IbEBMbyD KZDlnRN65w4gYwjO3Ls9cNns2AmCcReH8+AiNaIsTxWa3bwlrjDNSx6aIEbYu2n9l2 6PO6uVXfHfzM6zBhqO2PlB6c5cBviAM1TwizuQlqXGRslFrM/k0xXoTjUHHtReweR3 VDUkZL8Sxh1JA== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Wentao Liang , Hans Verkuil , Sasha Levin , s.nawrocki@samsung.com, mchehab@kernel.org, krzk@kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH AUTOSEL 6.14 066/102] media: platform: exynos4-is: Add hardware sync wait to fimc_is_hw_change_mode() Date: Sun, 1 Jun 2025 19:28:58 -0400 Message-Id: <20250601232937.3510379-66-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250601232937.3510379-1-sashal@kernel.org> References: <20250601232937.3510379-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.14.9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Wentao Liang [ Upstream commit bd9f6ce7d512fa21249415c16af801a4ed5d97b6 ] In fimc_is_hw_change_mode(), the function changes camera modes without waiting for hardware completion, risking corrupted data or system hangs if subsequent operations proceed before the hardware is ready. Add fimc_is_hw_wait_intmsr0_intmsd0() after mode configuration, ensuring hardware state synchronization and stable interrupt handling. Signed-off-by: Wentao Liang Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- Based on my analysis of the commit and examination of the kernel code, here is my assessment: **YES** This commit should be backported to stable kernel trees for the following reasons: ## Analysis of the Code Change The commit adds a single line `fimc_is_hw_wait_intmsr0_intmsd0(is);` at line 167 in the `fimc_is_hw_change_mode()` function in `drivers/media/platform/samsung/exynos4-is/fimc-is-regs.c`. ## Why This Should Be Backported 1. **Clear Bug Fix**: The commit message explicitly states this fixes a race condition where "the function changes camera modes without waiting for hardware completion, risking corrupted data or system hangs if subsequent operations proceed before the hardware is ready." This is a classic hardware synchronization bug. 2. **Consistent Pattern**: Examining the surrounding code shows that ALL other similar hardware control functions (`fimc_is_hw_get_setfile_addr()`, `fimc_is_hw_load_setfile()`, `fimc_is_hw_stream_on()`, `fimc_is_hw_stream_off()`) already call `fimc_is_hw_wait_intmsr0_intmsd0()` before writing to hardware registers. The `fimc_is_hw_change_mode()` function was the only outlier missing this synchronization. 3. **Minimal and Safe**: The change is extremely small (one line) and uses an existing, well-tested synchronization primitive. The `fimc_is_hw_wait_intmsr0_intmsd0()` function implements a timeout-based wait with proper error handling. 4. **Critical Subsystem**: This affects camera hardware control in Samsung Exynos4 SoCs. Hardware synchronization issues in camera drivers can cause: - System hangs (as mentioned in commit message) - Data corruption - Unpredictable hardware state 5. **Runtime Safety**: The wait function has built-in timeout protection (2000 iterations with 1μs delay each), so it cannot cause infinite hangs even if hardware fails. 6. **Follows Hardware Protocol**: The pattern clearly shows the proper hardware protocol is: wait for ready state → write command → trigger interrupt. The missing wait was a protocol violation. ## Comparison with Historical References Looking at the provided similar commits marked "NO" for backporting, they were all: - Documentation/binding changes (commits #1, #2) - Code cleanup/feature removal (commit #3) - Architecture changes (commit #4) The one commit marked "YES" (commit #5) was a simple bug fix correcting a return value check, very similar in nature to this synchronization fix. This commit fits the stable tree criteria perfectly: it's a small, contained bug fix addressing a real hardware synchronization issue that could cause system instability, with minimal risk of regression. drivers/media/platform/samsung/exynos4-is/fimc-is-regs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-is-regs.c b/drivers/media/platform/samsung/exynos4-is/fimc-is-regs.c index 366e6393817d2..5f9c44e825a5f 100644 --- a/drivers/media/platform/samsung/exynos4-is/fimc-is-regs.c +++ b/drivers/media/platform/samsung/exynos4-is/fimc-is-regs.c @@ -164,6 +164,7 @@ int fimc_is_hw_change_mode(struct fimc_is *is) if (WARN_ON(is->config_index >= ARRAY_SIZE(cmd))) return -EINVAL; + fimc_is_hw_wait_intmsr0_intmsd0(is); mcuctl_write(cmd[is->config_index], is, MCUCTL_REG_ISSR(0)); mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1)); mcuctl_write(is->setfile.sub_index, is, MCUCTL_REG_ISSR(2)); -- 2.39.5