From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
"Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>,
"Hans Verkuil" <hverkuil+cisco@kernel.org>,
"Sasha Levin" <sashal@kernel.org>,
lars@metafoo.de, linux-media@vger.kernel.org
Subject: [PATCH AUTOSEL 6.17-5.15] media: adv7180: Do not write format to device in set_fmt
Date: Sat, 25 Oct 2025 11:56:24 -0400 [thread overview]
Message-ID: <20251025160905.3857885-153-sashal@kernel.org> (raw)
In-Reply-To: <20251025160905.3857885-1-sashal@kernel.org>
From: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
[ Upstream commit 46c1e7814d1c3310ef23c01ed1a582ef0c8ab1d2 ]
The .set_fmt callback should not write the new format directly do the
device, it should only store it and have it applied by .s_stream.
The .s_stream callback already calls adv7180_set_field_mode() so it's
safe to remove programming of the device and just store the format and
have .s_stream apply it.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
YES
- Fixes incorrect behavior: The change enforces the V4L2 subdev rule
that .set_fmt should not program hardware but only update state, with
hardware programming deferred to .s_stream. In the new code, .set_fmt
(driver’s `adv7180_set_pad_format`) only stores the requested field
and does not touch the device, eliminating unintended runtime side
effects during format negotiation. See
`drivers/media/i2c/adv7180.c:784-793` where it now only assigns
`state->field` for ACTIVE formats and no longer toggles power or
programs registers.
- Safe because .s_stream already applies the format: The .s_stream path
powers the device off, configures it, then powers it on, and
explicitly applies the field mode. `adv7180_s_stream` calls
`init_device` when enabling, which calls `adv7180_set_field_mode`.
See:
- `drivers/media/i2c/adv7180.c:927-955` (.s_stream powers off, calls
`init_device`, powers on),
- `drivers/media/i2c/adv7180.c:844-859` (`init_device` calls
`adv7180_program_std` then `adv7180_set_field_mode` at
`drivers/media/i2c/adv7180.c:854`).
This guarantees the stored `state->field` is applied at the correct
time.
- Eliminates disruptive side effects: Previously, .set_fmt would power-
cycle the decoder and program field mode immediately (via
`adv7180_set_power(state, false)`, `adv7180_set_field_mode(state)`,
`adv7180_set_power(state, true)`), which could:
- Disrupt ongoing or prepared streaming sessions by unexpectedly
toggling power during format negotiation.
- Violate the expected V4L2 subdev semantics where format negotiation
should be side-effect-free.
The new behavior prevents these issues by staging only the state
change and deferring hardware ops to .s_stream.
- Consistency and correctness: The stored field influences both
negotiated format reporting and hardware setup when streaming starts:
- Format reporting uses `state->field` to compute height and field
(see `drivers/media/i2c/adv7180.c:700-709` and `759-761`).
- When powering on with CSI-2, `adv7180_set_power` also considers
`state->field` (e.g., sets CSI register 0x1D if progressive output
is used), ensuring consistent device programming once the stream
starts (see `drivers/media/i2c/adv7180.c:202-219`).
- Contained change, minimal risk:
- Single-file, localized change to adv7180 driver.
- No new features or ABI changes; aligns with established subdev
patterns.
- No architectural shifts; only removes premature device programming
from .set_fmt.
- The driver already centralizes device programming within the
streaming lifecycle, so behavior remains correct while avoiding
premature side effects.
- Stable suitability:
- Addresses a real behavioral bug (programming hardware during
.set_fmt) that can lead to video glitches or races during
negotiation.
- Small, targeted patch that reduces side effects and adheres to V4L2
best practices.
- Low regression risk provided the target stable trees have the same
pattern where .s_stream calls into `init_device` →
`adv7180_set_field_mode` (as in this tree). In this codebase, that
condition is satisfied.
Given these points, this is a good candidate for backporting to stable
media trees.
drivers/media/i2c/adv7180.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 84600fa75ae8a..8100fe6b0f1d4 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -812,14 +812,7 @@ static int adv7180_set_pad_format(struct v4l2_subdev *sd,
ret = adv7180_mbus_fmt(sd, &format->format);
if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
- if (state->field != format->format.field) {
- guard(mutex)(&state->mutex);
-
- state->field = format->format.field;
- adv7180_set_power(state, false);
- adv7180_set_field_mode(state);
- adv7180_set_power(state, true);
- }
+ state->field = format->format.field;
} else {
framefmt = v4l2_subdev_state_get_format(sd_state, 0);
*framefmt = format->format;
--
2.51.0
next prev parent reply other threads:[~2025-10-25 16:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251025160905.3857885-1-sashal@kernel.org>
2025-10-25 15:53 ` [PATCH AUTOSEL 6.17] media: nxp: imx8-isi: Fix streaming cleanup on release Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17] drm/xe: improve dma-resv handling for backup object Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-5.15] media: adv7180: Only validate format in querystd Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.6] media: ov08x40: Fix the horizontal flip control Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.15] media: em28xx: add special case for legacy gpiolib interface Sasha Levin
2025-10-27 9:24 ` Arnd Bergmann
2025-11-04 13:55 ` Sasha Levin
2025-10-25 15:56 ` Sasha Levin [this message]
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] media: imx-mipi-csis: Only set clock rate when specified in DT Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17] media: qcom: camss: csiphy-3ph: Add CSIPHY 2ph DPHY v2.0.1 init sequence Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] media: redrat3: use int type to store negative error codes Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-5.4] media: pci: ivtv: Don't create fake v4l2_fh Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-5.4] media: imon: make send_packet() more robust Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-5.15] media: adv7180: Add missing lock in suspend callback Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-6.1] media: verisilicon: Explicitly disable selection api ioctls for decoders Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-6.12] media: pci: mgb4: Fix timings comparison in VIDIOC_S_DV_TIMINGS Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-6.12] media: ipu6: isys: Set embedded data type correctly for metadata formats Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-6.1] media: i2c: og01a1b: Specify monochrome media bus format instead of Bayer Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.1] media: amphion: Delete v4l2_fh synchronously in .release() Sasha Levin
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=20251025160905.3857885-153-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hverkuil+cisco@kernel.org \
--cc=lars@metafoo.de \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox