From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796123789; b=einTug5hW6nVl97VMnyXWI4G1YLWkNKK2Yw86LAA7Bnxy193ZbNj4aGk2Zqaqkju5pIz GtH+cu00ag0rLMRQ5mv7rD5hu10YhKtpRZW3akX1yy2i1hJvpCxiBjTifdPsWpucLOAIW ZNofhK9w4CuGj3UwkeepUtFXoBrfmlYg2sOXEkcCEqPctirFy5HVVAkj4w6KIJi0wpLhc pplfwNbgaQG8DEsHu3MY2UVl/1Yovy1N4Dwvo5ngYoFUGGWGJQ71aUlDNoMOvRCDvjpbV m6h4XWyaiF5LQ2arFnIJqsSIBB3d6nszAQJoQ64tjPADtxbrDGgGo7hgs1ea+ALsd2A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796123789; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=fch6OlxQOlC8qg4RAU1tSaNrrf+V+6ZjvXYONGEbrV8=; b=ygkMg+0u6gVou3ZAL+jl4zUXkZbreYzXffK1bjgJir9BRVaXIVM0H3mfIz6Z13fd3Urt oYLJGNK+hIrFWosU+bkM1dLNuLJWtmpwpIVPkBNjfti66r+GzU0XyytvHP+pjIVnNVk6a ecHIela7Tc2YL1UV5++X95j+oECASe/QtP5dfyh7xp1w0qF+WZsg6lkl4nzr8Kh7y9JVH IvlODIPlczss5qQmGTqaTN+lCfWNZ68BYR6xTTka/NVXwarbuuTRbRsBn42z884P6KUdQ o6+a0LaPuPQPOIKkkaN4F1AZfiujNOxoLHGYKN8deuQES+eWrw6QYOwEELy652had7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="S/dureed"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0489606A33D for ; Tue, 1 Dec 2026 11:16:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S/dureed Received: by smtp.kernel.org (Postfix) with ESMTPSA id 169AA1F00897; Tue, 1 Dec 2026 11:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796123789; bh=fch6OlxQOlC8qg4RAU1tSaNrrf+V+6ZjvXYONGEbrV8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=S/dureedwsTmsaC3WLmY/lhU3XA0nDDpghyfjnPweuLFUrJ6362upv2P9+pNSX2VA IHQJWFIVv4WW/FzHaTBORKEscZLjXHhmYwxo7yDMYR9VBOe/NayXNrZF71/sn/9n4R DMFf+7aQDCHIAQmwMdrlHaT3aMD8MylGwHv9XyZkJer4mDx7NZzSc84oz1OX9eEWF+ fcRC88xtuVakfBmHF1OnvokAoZcAdNyoIFJufWpOUNHLWFc4Mv/hIFy4WrFWC4yU+R EqzgNXuWoc0t1QKjuwAiW6Er7KVhToqzZe8B5Y+IOiSd/GydyH320mQ69m1gFsH2yV xe17ymLFoqFCA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 2/2] media: i2c: Add Samsung S5K5E8 camera sensor driver Reply-To: sashiko-reviews@lists.linux.dev To: "Tuan Kiet Huynh" , devicetree@vger.kernel.org Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org In-Reply-To: <20261201110235.3327189-3-huynhtuankiet33@gmail.com> References: <20261201110235.3327189-1-huynhtuankiet33@gmail.com> <20261201110235.3327189-3-huynhtuankiet33@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 11:16:27 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D > + 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 =3D v4l2_subdev_get_locked_active_state(&s5k5e8->sd); > + if (WARN_ON_ONCE(!state)) > + return -EINVAL; > + > + mode =3D 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 =3D > + mode->height + ctrl->val - S5K5E8_EXPOSURE_MARGIN; > + exposure_def =3D min_t(s64, mode->exposure, exposure_max); > + ret =3D __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 =3D pm_runtime_get_if_active(s5k5e8->dev); > + if (!pm_status) > + return 0; > + > + switch (ctrl->id) { > + case V4L2_CID_ANALOGUE_GAIN: > + ret =3D cci_write(s5k5e8->regmap, S5K5E8_REG_AGAIN, ctrl->val, > + NULL); > + break; > + case V4L2_CID_EXPOSURE: > + ret =3D cci_write(s5k5e8->regmap, S5K5E8_REG_EXPOSURE, > + ctrl->val, NULL); > + break; > + case V4L2_CID_VBLANK: > + ret =3D cci_write(s5k5e8->regmap, S5K5E8_REG_VTS, > + ctrl->val + mode->height, NULL); > + break; > + case V4L2_CID_VFLIP: > + case V4L2_CID_HFLIP: > + ret =3D 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 =3D > + 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 =3D=3D V4L2_SUBDEV_FORMAT_ACTIVE && mode_changed) { > + hblank =3D mode->hts - mode->width; > + ret =3D __v4l2_ctrl_modify_range(s5k5e8->hblank, hblank, hblank, > + 1, hblank); > + if (ret) > + goto restore; > + > + vblank =3D mode->vts - mode->height; > + ret =3D __v4l2_ctrl_modify_range(s5k5e8->vblank, vblank, > + S5K5E8_VTS_MAX - mode->height, > + 1, vblank); > + if (ret) > + goto restore; > + > + ret =3D __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 =3D __v4l2_ctrl_s_ctrl(s5k5e8->exposure, mode->exposure); > + if (ret) > + goto restore; > + } > + > + return 0; > + > +restore: > + *format =3D old_format; > + *crop =3D old_crop; > + > + /* Best effort: restore the control ranges of the old mode. */ > + hblank =3D old_mode->hts - old_mode->width; > + __v4l2_ctrl_modify_range(s5k5e8->hblank, hblank, hblank, 1, hblank); > + vblank =3D 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 =3D 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 =3D v4l2_async_register_subdev_sensor(&s5k5e8->sd); > + if (ret < 0) { > + ret =3D 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 =3D=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201110235.3327= 189-1-huynhtuankiet33@gmail.com?part=3D2