Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hikmah Gumelar" <hikmahgumelar@gmail.com>
Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v3 5/7] media: i2c: add ov12a10 image sensor driver
Date: Mon, 23 Nov 2026 15:50:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-229613@kernel.org> (raw)
In-Reply-To: <20261123152722.168879-6-hikmahgumelar@gmail.com>

Thank you for your contribution! Sashiko AI review found 12 potential
issues to consider:
- [High] media: i2c: ov12a10: missing IS_ERR() GPIO checks and name
  mismatch in probe()
- [Medium] media: i2c: ov12a10: missing v4l2_subdev_cleanup() in probe()
  and remove()
- [Medium] media: i2c: ov12a10: missing vana_gpio rollback in
  ov12a10_power_on()
- [Medium] media: i2c: ov12a10: runtime PM bugs in ov12a10_probe() and
  ov12a10_set_ctrl()
- [Medium] media: i2c: ov12a10: missing exposure range update in
  ov12a10_set_ctrl()
- [Medium] media: i2c: ov12a10: missing test pattern enable bit in
  ov12a10_set_ctrl()
- [Medium] media: i2c: ov12a10: uninitialized subdev state in get_fmt()
  and set_fmt()
- [Medium] media: i2c: ov12a10: wrong native and crop rectangles in
  ov12a10_get_selection()
- [Low] media: i2c: ov12a10: missing fwnode endpoint and clk_set_rate()
  checks in ov12a10_probe()
- [Low] media: i2c: ov12a10: missing DEFINE_RUNTIME_DEV_PM_OPS() and
  pm_ptr()
- [Low] media: i2c: ov12a10: mismatched OV12A10_REG_EXPOSURE and unused
  macros
- [Low] media: i2c: ov12a10: coding style violations in struct, switch,
  and error labels
--

commit b4d54d6ecb617bf73cbccd2d0578b1858ed17a67
Author: Hikmah Gumelar <hikmahgumelar@gmail.com>

media: i2c: add ov12a10 image sensor driver

This commit adds a V4L2 subdevice driver for the OmniVision OV12A10 MIPI
CSI-2 image sensor supporting 1280x720 binned 10-bit Bayer output.

> diff --git a/drivers/media/i2c/ov12a10.c b/drivers/media/i2c/ov12a10.c
> new file mode 100644
> index 0000000000000..48e7a5e981972
> --- /dev/null
> +++ b/drivers/media/i2c/ov12a10.c
> @@ -0,0 +1,719 @@

[ ... ]

> +#define OV12A10_REG_MODE_SELECT		0x0100
> +#define OV12A10_MODE_STANDBY		0x00
> +#define OV12A10_MODE_STREAMING		0x01
> +#define OV12A10_REG_VTS			0x380e
> +#define OV12A10_REG_EXPOSURE		0x3501

[Severity: Low]
Should OV12A10_REG_EXPOSURE be defined as 0x3500 and used in
ov12a10_set_ctrl()?  The 24-bit exposure write in ov12a10_set_ctrl()
hardcodes 0x3500 (the MSB of 0x3500..0x3502), leaving OV12A10_REG_EXPOSURE
unused at 0x3501.  OV12A10_MODE_STREAMING is also unused because
ov12a10_set_stream() hardcodes { 0x0100, 0x01 } in stream_on_regs[].

[ ... ]

> +struct ov12a10_reg { u16 address;
> +u8 val;
> +};

[Severity: Low]
This isn't a bug, but struct ov12a10_reg does not follow kernel coding
style, and the same applies to the misaligned break statements in
ov12a10_set_ctrl() and the single-line goto labels at the bottom of
ov12a10_probe().

[ ... ]

> +static int ov12a10_power_on(struct device *dev)
> +{
> +	struct ov12a10 *ov12a10 = to_ov12a10(dev_get_drvdata(dev));
> +	int ret;
> +
> +	if (ov12a10->vana_gpio)
> +		gpiod_set_value_cansleep(ov12a10->vana_gpio, 1);
> +
> +	ret = regulator_bulk_enable(OV12A10_NUM_SUPPLIES, ov12a10->supplies);
> +	if (ret)
> +		return ret;
> +
> +	ret = clk_prepare_enable(ov12a10->xvclk);
> +	if (ret) {
> +		regulator_bulk_disable(OV12A10_NUM_SUPPLIES, ov12a10->supplies);
> +		return ret;
> +	}

[Severity: Medium]
Does ov12a10_power_on() leave vana_gpio asserted high when
regulator_bulk_enable() or clk_prepare_enable() fails?

[ ... ]

> +static int ov12a10_set_ctrl(struct v4l2_ctrl *ctrl)
> +{
> +	struct ov12a10 *ov12a10 = container_of(ctrl->handler, struct ov12a10, ctrl_handler);
> +	int ret = 0;
> +
> +	if (!pm_runtime_get_if_in_use(ov12a10->dev))
> +		return 0;

[Severity: Medium]
Should this check pm_runtime_get_if_in_use(ov12a10->dev) <= 0?  When
runtime PM is disabled (or CONFIG_PM is unset), pm_runtime_get_if_in_use()
returns -EINVAL without incrementing the usage count, so !ret is false and
ov12a10_set_ctrl() writes to I2C and calls an unbalanced pm_runtime_put()
that underflows dev->power.usage_count.

Also, in ov12a10_probe(), v4l2_async_register_subdev_sensor() is called
before pm_runtime_set_active() and pm_runtime_enable(), so if the receiver
binds synchronously during registration and starts streaming or sets
controls, runtime PM is still disabled and marked suspended.

> +	switch (ctrl->id) {
> +	case V4L2_CID_ANALOGUE_GAIN:
> +		ret = ov12a10_write_reg(ov12a10, OV12A10_REG_ANALOG_GAIN, 2, ctrl->val);
> +	break;
> +	case V4L2_CID_EXPOSURE:
> +		ret = ov12a10_write_reg(ov12a10, 0x3500, 3, ctrl->val << 4);
> +	break;
> +	case V4L2_CID_VBLANK:
> +		ret = ov12a10_write_reg(ov12a10, OV12A10_REG_VTS, 2,
> +				ov12a10->cur_mode->height + ctrl->val);
> +	break;

[Severity: Medium]
Does changing V4L2_CID_VBLANK need to update the range of
ov12a10->exposure via __v4l2_ctrl_modify_range() before the
pm_runtime_get_if_in_use() check?  Without that update, lowering vblank
down to its minimum of 124 (VTS = 844) leaves exposure's maximum at 3360
and default at 2400, allowing exposure values that exceed VTS.

> +	case V4L2_CID_TEST_PATTERN:
> +		ret = ov12a10_write_reg(ov12a10, OV12A10_REG_TEST_PATTERN, 1, ctrl->val);
> +	break;

[Severity: Medium]
Does writing ctrl->val directly to OV12A10_REG_TEST_PATTERN (0x5080) leave
the test pattern generator disabled?  On OmniVision sensors using register
0x5080, BIT(7) is the test pattern enable bit and non-zero menu selections
map to (ctrl->val - 1) | BIT(7).

[ ... ]

> +static int ov12a10_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state,
> +		struct v4l2_subdev_format *fmt)
> +{
> +	struct ov12a10 *ov12a10 = to_ov12a10(sd);
> +
> +	fmt->format = (fmt->which == V4L2_SUBDEV_FORMAT_TRY) ? *v4l2_subdev_state_get_format(sd_state,
> +			fmt->pad) : fmt->format;
> +	if (fmt->which != V4L2_SUBDEV_FORMAT_TRY)
> +		ov12a10_update_pad_format(ov12a10->cur_mode, &fmt->format);
> +	return 0;
> +}
> +
> +static int ov12a10_set_format(struct v4l2_subdev *sd, const struct v4l2_subdev_client_info *ci, struct v4l2_subdev_state *sd_state,
> +		struct v4l2_subdev_format *fmt)
> +{
> +	struct ov12a10 *ov12a10 = to_ov12a10(sd);
> +
> +	ov12a10_update_pad_format(&supported_modes[0], &fmt->format);
> +	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
> +		*v4l2_subdev_state_get_format(sd_state, fmt->pad) = fmt->format;
> +	else
> +		ov12a10->cur_mode = &supported_modes[0];
> +
> +	return 0;
> +}

[Severity: Medium]
Does this leave sd->active_state unpopulated and active format queries
partially uninitialized?

ov12a10_probe() calls v4l2_subdev_init_finalize(), which allocates
sd->active_state and initializes it via internal_ops->init_state.  Because
ov12a10_internal_ops implements .open instead of .init_state, and
ov12a10_set_format() only writes to v4l2_subdev_state_get_format(sd_state,
fmt->pad) when fmt->which == V4L2_SUBDEV_FORMAT_TRY, sd->active_state
stays zeroed.  In addition, when fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE,
ov12a10_get_format() self-assigns fmt->format and calls
ov12a10_update_pad_format(), which only sets width, height, code, field,
and colorspace, leaving ycbcr_enc, quantization, xfer_func, and flags
uninitialized for in-kernel callers such as
v4l2_subdev_link_validate_get_format().

Implementing .init_state in ov12a10_internal_ops, unconditionally updating
*v4l2_subdev_state_get_format(sd_state, fmt->pad) in ov12a10_set_format(),
and using v4l2_subdev_get_fmt as .get_fmt would fix all three issues.

[ ... ]

> +static int ov12a10_get_selection(struct v4l2_subdev *sd, const struct v4l2_subdev_client_info *ci,
> +				struct v4l2_subdev_state *sd_state,
> +				struct v4l2_subdev_selection *sel)
> +{
> +	switch (sel->target) {
> +	case V4L2_SEL_TGT_CROP:
> +	case V4L2_SEL_TGT_CROP_DEFAULT:
> +	case V4L2_SEL_TGT_CROP_BOUNDS:
> +	case V4L2_SEL_TGT_NATIVE_SIZE:
> +		sel->r.left = 0;
> +		sel->r.top = 0;
> +		sel->r.width = 1280;
> +		sel->r.height = 720;
> +		return 0;
> +	default:
> +		return -EINVAL;
> +	}
> +}

[Severity: Medium]
Should ov12a10_get_selection() report the full 12MP pixel array for
V4L2_SEL_TGT_NATIVE_SIZE / CROP_BOUNDS / CROP_DEFAULT and the pre-binning
analog crop window for V4L2_SEL_TGT_CROP?

In ov12a10_common_regs, the full sensor array is 4112x3088 (active
4096x3072), and in ov12a10_1280x720_regs registers 0x3800..0x3807
configure an analog crop window from (800, 872) to (3391, 2343) before 2x2
binning down to 1280x720.  Returning (0, 0, 1280, 720) for all targets
misreports the sensor geometry and binning factor to userspace camera
stacks.

[ ... ]

> +static int ov12a10_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct ov12a10 *ov12a10;
> +	u32 val = 0;
> +	unsigned int i;
> +	int ret;
> +
> +	ov12a10 = devm_kzalloc(dev, sizeof(*ov12a10), GFP_KERNEL);
> +	if (!ov12a10)
> +		return -ENOMEM;
> +	ov12a10->dev = dev;
> +	v4l2_i2c_subdev_init(&ov12a10->sd, client, &ov12a10_subdev_ops);
> +	ov12a10->xvclk = devm_v4l2_sensor_clk_get(dev, NULL);
> +	if (IS_ERR(ov12a10->xvclk))
> +		return dev_err_probe(dev, PTR_ERR(ov12a10->xvclk), "xvclk\n");
> +	clk_set_rate(ov12a10->xvclk, OV12A10_XVCLK_FREQ);

[Severity: Low]
Should ov12a10_probe() check the return value of clk_set_rate() and
validate the MIPI CSI-2 fwnode endpoint?  The DT binding requires a
4-lane CSI-2 endpoint with a 216 MHz link-frequencies property, but the
driver never parses the endpoint with v4l2_fwnode_endpoint_alloc_parse().

> +	ov12a10->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> +	ov12a10->vana_gpio = devm_gpiod_get_optional(dev, "vana", GPIOD_OUT_LOW);
> +	ov12a10->pwdn_gpio = devm_gpiod_get_optional(dev, "pwdn", GPIOD_OUT_HIGH);
> +	if (IS_ERR(ov12a10->reset_gpio))
> +		return dev_err_probe(dev, PTR_ERR(ov12a10->reset_gpio), "reset\n");

[Severity: High]
What happens if devm_gpiod_get_optional() returns an error pointer (such
as -EPROBE_DEFER) for vana_gpio or pwdn_gpio?  Because neither pointer is
checked with IS_ERR(), the non-NULL ERR_PTR is stored and passed straight
to gpiod_set_value_cansleep() in ov12a10_power_on() instead of deferring
or aborting probe.

Also, the DT binding (Documentation/devicetree/bindings/media/i2c/ovti,ov12a10.yaml)
defines powerdown-gpios rather than pwdn-gpios (and does not document
vana-gpios), so requesting "pwdn" will never match a conforming DT.

[ ... ]

> +	ret = v4l2_subdev_init_finalize(&ov12a10->sd);
> +	if (ret)
> +		goto err_media;
> +	ret = v4l2_async_register_subdev_sensor(&ov12a10->sd);
> +	if (ret)
> +		goto err_media;
> +	pm_runtime_set_active(dev);
> +	pm_runtime_enable(dev);
> +	pm_runtime_idle(dev);
> +	return 0;
> +err_media: media_entity_cleanup(&ov12a10->sd.entity);
> +err_ctrl: v4l2_ctrl_handler_free(ov12a10->sd.ctrl_handler);
> +err_mutex: mutex_destroy(&ov12a10->mutex);
> +err_power: ov12a10_power_off(dev);
> +	return ret;
> +}
> +
> +static void ov12a10_remove(struct i2c_client *client)
> +{
> +	struct v4l2_subdev *sd = i2c_get_clientdata(client);
> +	struct ov12a10 *ov12a10 = to_ov12a10(sd);
> +
> +	v4l2_async_unregister_subdev(sd);
> +	media_entity_cleanup(&sd->entity);
> +	v4l2_ctrl_handler_free(sd->ctrl_handler);

[Severity: Medium]
Does missing v4l2_subdev_cleanup(sd) in ov12a10_remove() and on the
v4l2_async_register_subdev_sensor() error path in ov12a10_probe() leak
sd->active_state?  v4l2_subdev_init_finalize() allocates sd->active_state
and its pad array, which are only freed by v4l2_subdev_cleanup().

[ ... ]

> +static const struct dev_pm_ops ov12a10_pm_ops = { SET_RUNTIME_PM_OPS(ov12a10_power_off,
> +		ov12a10_power_on, NULL) };
> +static const struct of_device_id ov12a10_of_match[] = { { .compatible = "ovti,ov12a10" }, { } };
> +MODULE_DEVICE_TABLE(of, ov12a10_of_match);
> +static struct i2c_driver ov12a10_i2c_driver = {
> +	.driver = { .name = "ov12a10", .pm = &ov12a10_pm_ops, .of_match_table = ov12a10_of_match },

[Severity: Low]
Could ov12a10_pm_ops use DEFINE_RUNTIME_DEV_PM_OPS() and be wired with
.pm = pm_ptr(&ov12a10_pm_ops) so the PM ops are dropped when CONFIG_PM is
disabled?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123152722.168879-1-hikmahgumelar@gmail.com?part=5

  reply	other threads:[~2026-11-23 15:50 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 11:07 [PATCH 0/6] arm64: dts: qcom: msm8953-xiaomi-tissot: enable front and rear cameras Hikmah Gumelar
2026-11-23 11:08 ` [PATCH 1/6] clk: qcom: gcc-msm8953: fix csi_phytimer_clk_src 100MHz parent Hikmah Gumelar
2026-11-23 11:08 ` [PATCH 2/6] media: dt-bindings: media: i2c: add Samsung S5K5E8 Hikmah Gumelar
2026-11-23 15:11   ` Rob Herring (Arm)
2026-11-23 11:08 ` [PATCH 3/6] media: i2c: add s5k5e8 image sensor driver Hikmah Gumelar
2026-11-23 11:08 ` [PATCH 4/6] media: dt-bindings: media: i2c: add OmniVision OV12A10 Hikmah Gumelar
2026-11-23 11:08 ` [PATCH 5/6] media: i2c: add ov12a10 image sensor driver Hikmah Gumelar
2026-11-23 11:08 ` [PATCH 6/6] arm64: dts: qcom: msm8953-xiaomi-tissot: enable front and rear cameras Hikmah Gumelar
2026-11-23 12:35 ` [PATCH v2 0/7] " Hikmah Gumelar
2026-11-23 12:35   ` [PATCH v2 1/7] clk: qcom: gcc-msm8953: fix csi_phytimer_clk_src 100MHz parent Hikmah Gumelar
2026-11-23 12:42     ` sashiko-bot
2026-11-23 12:35   ` [PATCH v2 2/7] media: dt-bindings: media: i2c: add Samsung S5K5E8 Hikmah Gumelar
2026-11-23 12:43     ` sashiko-bot
2026-11-23 15:11     ` Rob Herring (Arm)
2026-11-23 12:35   ` [PATCH v2 3/7] media: i2c: add s5k5e8 image sensor driver Hikmah Gumelar
2026-11-23 12:52     ` sashiko-bot
2026-11-23 13:56     ` Uwe Kleine-König
2026-11-23 14:14       ` Hikmah Gumelar
2026-11-23 12:35   ` [PATCH v2 4/7] media: dt-bindings: media: i2c: add OmniVision OV12A10 Hikmah Gumelar
2026-11-23 12:45     ` sashiko-bot
2026-11-23 15:11     ` Rob Herring (Arm)
2026-11-23 12:35   ` [PATCH v2 5/7] media: i2c: add ov12a10 image sensor driver Hikmah Gumelar
2026-11-23 12:57     ` sashiko-bot
2026-11-23 12:35   ` [PATCH v2 6/7] arm64: dts: qcom: msm8953: add CAMSS node and MCLK pinctrl states Hikmah Gumelar
2026-11-23 12:49     ` sashiko-bot
2026-11-23 12:35   ` [PATCH v2 7/7] arm64: dts: qcom: msm8953-xiaomi-tissot: enable front and rear cameras Hikmah Gumelar
2026-11-23 12:52     ` sashiko-bot
2026-11-23 15:27   ` [PATCH v3 0/7] " Hikmah Gumelar
2026-11-23 15:27     ` [PATCH v3 1/7] clk: qcom: gcc-msm8953: fix csi_phytimer_clk_src 100MHz parent Hikmah Gumelar
2026-11-23 15:27     ` [PATCH v3 2/7] media: dt-bindings: media: i2c: add Samsung S5K5E8 Hikmah Gumelar
2026-11-23 15:27     ` [PATCH v3 3/7] media: i2c: add s5k5e8 image sensor driver Hikmah Gumelar
2026-11-23 15:53       ` sashiko-bot
2026-11-23 15:27     ` [PATCH v3 4/7] media: dt-bindings: media: i2c: add OmniVision OV12A10 Hikmah Gumelar
2026-11-23 15:27     ` [PATCH v3 5/7] media: i2c: add ov12a10 image sensor driver Hikmah Gumelar
2026-11-23 15:50       ` sashiko-bot [this message]
2026-11-23 15:27     ` [PATCH v3 6/7] arm64: dts: qcom: msm8953: add CAMSS node and MCLK pinctrl states Hikmah Gumelar
2026-11-23 15:27     ` [PATCH v3 7/7] arm64: dts: qcom: msm8953-xiaomi-tissot: enable front and rear cameras Hikmah Gumelar
2026-11-23 15:46       ` sashiko-bot

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-229613@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hikmahgumelar@gmail.com \
    --cc=linux-clk@vger.kernel.org \
    --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