From: sashiko-bot@kernel.org
To: "Tuan Kiet Huynh" <huynhtuankiet33@gmail.com>,
devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v4 2/2] media: i2c: Add Samsung S5K5E8 camera sensor driver
Date: Tue, 01 Dec 2026 11:16:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-243145@kernel.org> (raw)
In-Reply-To: <20261201110235.3327189-3-huynhtuankiet33@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] media: i2c: s5k5e8: stale pad format code on flip in
s5k5e8_set_ctrl()
- [Medium] media: i2c: s5k5e8: skipped exposure range update in
s5k5e8_set_pad_format()
- [Medium] media: i2c: s5k5e8: double power-off on error in
s5k5e8_probe()
--
commit 80073db7588e5bb612eb448a1a6e71dcce3b2a95
Author: Andrii Cherniavskyi <chernyav.a@gmail.com>
media: i2c: Add Samsung S5K5E8 camera sensor driver
This commit adds a V4L2 subdevice driver for the Samsung S5K5E8 5-megapixel
MIPI CSI-2 image sensor.
> diff --git a/drivers/media/i2c/s5k5e8.c b/drivers/media/i2c/s5k5e8.c
> new file mode 100644
> index 0000000000000..8a3d034243514
> --- /dev/null
> +++ b/drivers/media/i2c/s5k5e8.c
> @@ -0,0 +1,1108 @@
[ ... ]
> +static int s5k5e8_set_ctrl(struct v4l2_ctrl *ctrl)
> +{
> + struct s5k5e8 *s5k5e8 =
> + container_of(ctrl->handler, struct s5k5e8, ctrl_handler);
> + struct v4l2_subdev_state *state;
> + const struct s5k5e8_mode *mode;
> + s64 exposure_max, exposure_def;
> + int pm_status;
> + int ret;
> +
> + state = v4l2_subdev_get_locked_active_state(&s5k5e8->sd);
> + if (WARN_ON_ONCE(!state))
> + return -EINVAL;
> +
> + mode = s5k5e8_get_mode_from_state(state);
> +
> + /* Propagate change of current control to all related controls */
> + switch (ctrl->id) {
> + case V4L2_CID_VBLANK:
> + /* Update max exposure while meeting expected vblanking */
> + exposure_max =
> + mode->height + ctrl->val - S5K5E8_EXPOSURE_MARGIN;
> + exposure_def = min_t(s64, mode->exposure, exposure_max);
> + ret = __v4l2_ctrl_modify_range(s5k5e8->exposure,
> + s5k5e8->exposure->minimum,
> + exposure_max,
> + s5k5e8->exposure->step,
> + exposure_def);
> + if (ret)
> + return ret;
> + break;
> + }
> +
> + /* V4L2 controls are applied when sensor is powered up for streaming */
> + pm_status = pm_runtime_get_if_active(s5k5e8->dev);
> + if (!pm_status)
> + return 0;
> +
> + switch (ctrl->id) {
> + case V4L2_CID_ANALOGUE_GAIN:
> + ret = cci_write(s5k5e8->regmap, S5K5E8_REG_AGAIN, ctrl->val,
> + NULL);
> + break;
> + case V4L2_CID_EXPOSURE:
> + ret = cci_write(s5k5e8->regmap, S5K5E8_REG_EXPOSURE,
> + ctrl->val, NULL);
> + break;
> + case V4L2_CID_VBLANK:
> + ret = cci_write(s5k5e8->regmap, S5K5E8_REG_VTS,
> + ctrl->val + mode->height, NULL);
> + break;
> + case V4L2_CID_VFLIP:
> + case V4L2_CID_HFLIP:
> + ret = cci_write(s5k5e8->regmap, S5K5E8_REG_ORIENTATION,
> + (s5k5e8->vflip->val ? S5K5E8_VFLIP : 0) |
> + (s5k5e8->hflip->val ? S5K5E8_HFLIP : 0),
> + NULL);
> + /* Only report the flipped Bayer order once the sensor has it. */
> + if (!ret)
> + v4l2_subdev_state_get_format(state, 0)->code =
> + s5k5e8_get_format_code(s5k5e8->hflip->val,
> + s5k5e8->vflip->val);
> + break;
[Severity: Medium]
Does changing V4L2_CID_HFLIP or V4L2_CID_VFLIP while the sensor is
runtime-suspended leave the active pad format's media bus code stale?
Because s5k5e8_enable_streams() grabs hflip and vflip while streaming,
userspace normally modifies them when the device is idle and suspended.
In that state pm_runtime_get_if_active() returns 0, so the V4L2 core
commits the new flip values to cur.val while
v4l2_subdev_state_get_format(state, 0)->code stays unflipped.
s5k5e8_enum_mbus_code() and s5k5e8_enum_frame_size() then report the new
flipped Bayer code from cur.val, whereas VIDIOC_SUBDEV_G_FMT and pipeline
link validation before streaming see the old code.
[ ... ]
> +static int s5k5e8_set_pad_format(struct v4l2_subdev *sd,
> + const struct v4l2_subdev_client_info *ci,
> + struct v4l2_subdev_state *state,
> + struct v4l2_subdev_format *fmt)
> +{
[ ... ]
> + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE && mode_changed) {
> + hblank = mode->hts - mode->width;
> + ret = __v4l2_ctrl_modify_range(s5k5e8->hblank, hblank, hblank,
> + 1, hblank);
> + if (ret)
> + goto restore;
> +
> + vblank = mode->vts - mode->height;
> + ret = __v4l2_ctrl_modify_range(s5k5e8->vblank, vblank,
> + S5K5E8_VTS_MAX - mode->height,
> + 1, vblank);
> + if (ret)
> + goto restore;
> +
> + ret = __v4l2_ctrl_s_ctrl(s5k5e8->vblank, vblank);
> + if (ret)
> + goto restore;
> +
> + /*
> + * No explicit exposure range update here: setting VBLANK
> + * above already updated the exposure range through
> + * s5k5e8_set_ctrl().
> + */
> + ret = __v4l2_ctrl_s_ctrl(s5k5e8->exposure, mode->exposure);
> + if (ret)
> + goto restore;
> + }
> +
> + return 0;
> +
> +restore:
> + *format = old_format;
> + *crop = old_crop;
> +
> + /* Best effort: restore the control ranges of the old mode. */
> + hblank = old_mode->hts - old_mode->width;
> + __v4l2_ctrl_modify_range(s5k5e8->hblank, hblank, hblank, 1, hblank);
> + vblank = old_mode->vts - old_mode->height;
> + __v4l2_ctrl_modify_range(s5k5e8->vblank, vblank,
> + S5K5E8_VTS_MAX - old_mode->height, 1, vblank);
> + __v4l2_ctrl_s_ctrl(s5k5e8->vblank, vblank);
> + __v4l2_ctrl_s_ctrl(s5k5e8->exposure, old_mode->exposure);
> +
> + return ret;
> +}
[Severity: Medium]
Can relying on __v4l2_ctrl_s_ctrl(s5k5e8->vblank, vblank) skip the
s5k5e8->exposure range update when switching modes?
Both __v4l2_ctrl_modify_range() and __v4l2_ctrl_s_ctrl() only invoke
s5k5e8_set_ctrl() when the control value actually changes from cur.val.
If userspace sets V4L2_CID_VBLANK to 29 in the 2592x1944 mode and then
switches to the 1304x980 mode (where the default vblank is also 1009 - 980
= 29), s5k5e8_set_ctrl() is not called, leaving s5k5e8->exposure->maximum
at 1969 instead of 1005 (and skipping the S5K5E8_REG_VTS write if the
sensor is runtime-active). For the same reason, if
__v4l2_ctrl_s_ctrl(s5k5e8->vblank, vblank) fails during cci_write() after
modifying the exposure range, vblank->cur.val is still the old mode's
vblank, so the restore path will not roll back the exposure range either.
[ ... ]
> + pm_runtime_set_active(s5k5e8->dev);
> + pm_runtime_set_autosuspend_delay(s5k5e8->dev, 1000);
> + pm_runtime_use_autosuspend(s5k5e8->dev);
> + pm_runtime_enable(s5k5e8->dev);
> +
> + ret = v4l2_async_register_subdev_sensor(&s5k5e8->sd);
> + if (ret < 0) {
> + ret = dev_err_probe(s5k5e8->dev, ret,
> + "failed to register V4L2 subdev\n");
> + goto subdev_cleanup;
> + }
> +
> + pm_runtime_idle(s5k5e8->dev);
> +
> + return 0;
> +
> +subdev_cleanup:
> + pm_runtime_dont_use_autosuspend(s5k5e8->dev);
> + pm_runtime_disable(s5k5e8->dev);
> + pm_runtime_set_suspended(s5k5e8->dev);
> + v4l2_subdev_cleanup(&s5k5e8->sd);
> +
> +media_entity_cleanup:
> + media_entity_cleanup(&s5k5e8->sd.entity);
> +
> +v4l2_ctrl_handler_free:
> + v4l2_ctrl_handler_free(s5k5e8->sd.ctrl_handler);
> +
> +power_off:
> + s5k5e8_power_off(s5k5e8->dev);
> +
> + return ret;
> +}
[Severity: Medium]
Does the subdev_cleanup error path call s5k5e8_power_off() twice if
v4l2_async_register_subdev_sensor() fails?
Runtime PM is enabled with the device active and usage_count == 0, so
calling pm_runtime_dont_use_autosuspend() before pm_runtime_disable()
triggers an immediate rpm_idle() -> rpm_suspend() that runs
s5k5e8_power_off(). Falling through to the power_off label then calls
s5k5e8_power_off() a second time, causing unbalanced clk_disable_unprepare()
and regulator_disable() calls.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201110235.3327189-1-huynhtuankiet33@gmail.com?part=2
prev parent reply other threads:[~2026-12-01 11:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 11:02 [PATCH v4 0/2] media: i2c: Add Samsung S5K5E8 camera sensor driver Tuan Kiet Huynh
2026-12-01 11:02 ` [PATCH v4 1/2] dt-bindings: media: i2c: Add Samsung S5K5E8 image sensor Tuan Kiet Huynh
2026-12-01 11:02 ` [PATCH v4 2/2] media: i2c: Add Samsung S5K5E8 camera sensor driver Tuan Kiet Huynh
2026-12-01 11:16 ` sashiko-bot [this message]
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=sashiko-outbox-243145@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=huynhtuankiet33@gmail.com \
--cc=media-ci@linuxtv.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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