Skip to contentSkip to conversation

media: i2c: Add onsemi AR0234 camera sensor driver

PATCH In review Alexander Shiyan 3 participants 6 messages Aug 7 – Aug 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover media: i2c: Add onsemi AR0234 camera sensor driver

This series adds a driver for the onsemi AR0234 CMOS image sensor. The AR0234 is a 1/2.6-inch global-shutter sensor with a 1940x1220 pixel array, capable of 1920x1200 resolution at up to 120 fps. It supports MIPI CSI-2 output with 1 to 4 data lanes, raw Bayer (8/10-bit) and monochrome formats, as well as DPCM 10->8 compression.

The driver has been tested with 2 and 4 lanes on an ARM64 Rockchip RK3588 platform with a 27 MHz external clock. Both 8-bit and 10-bit raw Bayer modes are functional.

Notes:
- 1-lane mode is currently disabled; attempts to use it produced no valid image.

[root@diasom-evb ~]# v4l2-compliance -u 2
v4l2-compliance 1.28.1, 64 bits, 64-bit time_t

Compliance test for device /dev/v4l-subdev2:

Driver Info:
ar0234 9-0018: ================= START STATUS ================= ar0234 9-0018: ================== END STATUS ==================

        Driver version   : 7.1.0
        Capabilities     : 0x00000000
        Client Capabilities: 0x0000000000000002

interval-uses-which
Required ioctls:
test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev2 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 20 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)

Total for device /dev/v4l-subdev2: 45, Succeeded: 45, Failed: 0, Warnings: 0

V1 -> V2:
- Fixed bugs reported by sashiko-bot:
- [Low] The compatible property schema contains fatal YAML syntax errors due to missing list hyphens (-), resulting in invalid JSON schema constructs that will fail dt_binding_check.
- [Low] The data-lanes schema constraint mathematically allows 3 lanes, which contradicts the explicit 2-or-4 lane hardware requirement described in the binding.
- [Critical] Incorrect clamping order in crop selection bounds calculation causes unsigned integer underflow, bypassing bounds checks.
- [High] Incorrect validation of pm_runtime_get_if_active() allows execution to proceed on negative error codes, leading to a usage counter underflow.
- [High] Missing v4l2_subdev_cleanup() causes a memory leak of the subdevice active state.
- [High] Static hblank lower bounds permit dynamic line length reduction below the absolute hardware minimum.
- [High] Potential division by zero during delay calculation if the clock rate is zero.
- [Medium] Unlocked V4L2 control helpers are called during initialization without acquiring the control handler lock, triggering a lockdep splat.
- [Medium] Mixing goto-based error handling with scope-based __free() cleanup in the same function violates API guidelines.
- [Medium] Changing the crop height fails to update exposure control limits reliably.
- [Medium] The active format state is modified before verifying PLL configuration, leaving state inconsistent on error.
- [Medium] Unlocked access to shared format state in ar0234_get_frame_desc.
- [Low] Using DIV_ROUND_UP with a 64-bit numerator causes a link error on 32-bit architectures.

Alexander Shiyan (2):
dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding
media: i2c: Add onsemi AR0234 image sensor driver

 .../bindings/media/i2c/onnn,ar0234.yaml       |  126 ++
 drivers/media/i2c/Kconfig                     |   12 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/ar0234.c                    | 1290 +++++++++++++++++
 4 files changed, 1429 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
 create mode 100644 drivers/media/i2c/ar0234.c
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 1/2 dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---
 .../bindings/media/i2c/onnn,ar0234.yaml       | 126 ++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +126 -0
new file mode 100644
index 000000000000..d6db435be9e2
@@ -0,0 +1,126 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/i2c/onnn,ar0234.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ON Semiconductor AR0234 1/2.6-inch CMOS Digital Image Sensor
+
+maintainers:
+  - Alexander Shiyan <[email protected]>
+
+description:
+  The AR0234 is a 1/2.6-inch CMOS digital image sensor with a pixel
+  array of 1940x1220 pixels, capable of 1920x1200 resolution at up
+  to 120 fps. It supports MIPI CSI-2 output with 2 or 4 data lanes,
+  color raw Bayer (8/10-bit) or monochrome output.
+
+properties:
+  compatible:
+    oneOf:
+      - const: onnn,ar0234cs
+      - items:
+          - enum: ["onnn,ar0234cssc", "onnn,ar0234cssm"]
+          - const: onnn,ar0234cs
+
+  reg:
+    description: I2C device address
+    maxItems: 1
+
+  clocks:
+    description: Reference clock (external clock) input
+    maxItems: 1
+
+  reset-gpios:
+    description: Reset pin, usually active low (if needed)
+    maxItems: 1
+
+  vaa-supply:
+    description: Analog (2.8V) supply regulator
+
+  vdd-supply:
+    description: Digital Core (1.2V) supply regulator
+
+  vddio-supply:
+    description: I/O (1.8V-2.8V) supply regulator
+
+  orientation: true
+  rotation: true
+
+  port:
+    $ref: /schemas/graph.yaml#/$defs/port-base
+    description: CSI-2 transmitter port
+    additionalProperties: false
+    properties:
+      endpoint:
+        $ref: /schemas/media/video-interfaces.yaml#
+        unevaluatedProperties: false
+        properties:
+          data-lanes:
+            description: Number of MIPI CSI-2 data lanes
+            oneOf:
+              - items:
+                  enum: [1, 2]
+                minItems: 2
+                maxItems: 2
+              - items:
+                  enum: [1, 2, 3, 4]
+                minItems: 4
+                maxItems: 4
+
+          link-frequencies:
+            description:
+              Allowed MIPI link frequencies in Hz. Two frequencies must
+              be provided, one for 8-bit mode and another for 10-bit mode.
+              Each frequency shall be within the sensor valid operating
+              range.
+            minItems: 2
+            maxItems: 2
+            items:
+              minimum: 360000000
+              maximum: 450000000
+
+        required:
+          - data-lanes
+          - link-frequencies
+
+    required:
+      - endpoint
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        camera@18 {
+            compatible = "onnn,ar0234cssc", "onnn,ar0234cs";
+            reg = <0x18>;
+            pinctrl-names = "default";
+            pinctrl-0 = <&pinctrl_cam>;
+            clocks = <&clk27m>;
+            vaa-supply = <&reg_cam_vaa>;
+            vdd-supply = <&reg_cam_vdd>;
+            vddio-supply = <&reg_cam_vddio>;
+            reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>;
+
+            port {
+                ar0234_out: endpoint {
+                    data-lanes = <1 2 3 4>;
+                    link-frequencies = /bits/ 64 <360000000 450000000>;
+                    remote-endpoint = <&ar0234_in>;
+                };
+            };
+        };
+    };
+...
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Standard properties 'orientation' and 'rotation' bypass standard type validation. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Standard properties 'orientation' and 'rotation' bypass standard type validation. --

--- Patch [1]: [PATCH v2 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding --- commit d490efc51c8d22ea84e9e5b16150e2d9e4816d7b
Author: Alexander Shiyan <[email protected]>

dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

This commit adds a devicetree binding for the onsemi AR0234 CMOS image sensor.

Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +0 -0
new file mode 100644

[ ... ]

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 48

Quoted 8 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +8 -0
+  vdd-supply:
+    description: Digital Core (1.2V) supply regulator
+
+  vddio-supply:
+    description: I/O (1.8V-2.8V) supply regulator
+
+  orientation: true
+  rotation: true

[Severity: Low]
Does declaring these standard properties as 'true' bypass the strict type and enum validation defined in video-interface-devices.yaml?

It looks like this is done to circumvent the 'additionalProperties: false' constraint, but it would allow device trees with malformed values for orientation or rotation to silently pass schema validation.

Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +4 -0
+
+  port:
+    $ref: /schemas/graph.yaml#/$defs/port-base
+    description: CSI-2 transmitter port

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding

In reply to Alexander Shiyan
Quoted 27 lines · Alexander Shiyan

Add devicetree binding for the onsemi AR0234 CMOS image sensor.

---
 .../bindings/media/i2c/onnn,ar0234.yaml       | 126 ++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +13 -0
new file mode 100644
index 000000000000..d6db435be9e2
@@ -0,0 +1,126 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/i2c/onnn,ar0234.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ON Semiconductor AR0234 1/2.6-inch CMOS Digital Image Sensor
+
+maintainers:
+  - Alexander Shiyan <[email protected]>
+
+description:
+  The AR0234 is a 1/2.6-inch CMOS digital image sensor with a pixel

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 23

Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +10 -0
+  array of 1940x1220 pixels, capable of 1920x1200 resolution at up
+  to 120 fps. It supports MIPI CSI-2 output with 2 or 4 data lanes,
+  color raw Bayer (8/10-bit) or monochrome output.
+
+properties:
+  compatible:
+    oneOf:
+      - const: onnn,ar0234cs
+      - items:
+          - enum: ["onnn,ar0234cssc", "onnn,ar0234cssm"]

- enum:
- onnn,ar0234cssc
- onnn,ar0234cssm

Please explain somewhere what the differences between the 3 cases are.

Quoted 15 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +15 -0
+          - const: onnn,ar0234cs
+
+  reg:
+    description: I2C device address
+    maxItems: 1
+
+  clocks:
+    description: Reference clock (external clock) input
+    maxItems: 1
+
+  reset-gpios:
+    description: Reset pin, usually active low (if needed)
+    maxItems: 1
+
+  vaa-supply:

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 48

Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +10 -0
+    description: Analog (2.8V) supply regulator
+
+  vdd-supply:
+    description: Digital Core (1.2V) supply regulator
+
+  vddio-supply:
+    description: I/O (1.8V-2.8V) supply regulator
+
+  orientation: true
+  rotation: true

You need a reference to video-interface-device.yaml if you are going to use these.

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 53

Quoted 5 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +5 -0
+
+  port:
+    $ref: /schemas/graph.yaml#/$defs/port-base
+    description: CSI-2 transmitter port
+    additionalProperties: false

blank line

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 57

Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +4 -0
+    properties:
+      endpoint:
+        $ref: /schemas/media/video-interfaces.yaml#
+        unevaluatedProperties: false

blank line

Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 63

Quoted 6 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +6 -0
+        properties:
+          data-lanes:
+            description: Number of MIPI CSI-2 data lanes
+            oneOf:
+              - items:
+                  enum: [1, 2]

Is any order allowed? That implies some sort of lane remapping. If that's not supported, then see pretty much any other binding for an example of what this should look like.

Quoted 6 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +6 -0
+                minItems: 2
+                maxItems: 2
+              - items:
+                  enum: [1, 2, 3, 4]
+                minItems: 4
+                maxItems: 4
#4 lore raw

PATCH v2 2/2 media: i2c: Add onsemi AR0234 image sensor driver

In reply to Alexander Shiyan

Add driver for the onsemi AR0234 CMOS image sensor.

---
 drivers/media/i2c/Kconfig  |   12 +
 drivers/media/i2c/Makefile |    1 +
 drivers/media/i2c/ar0234.c | 1290 ++++++++++++++++++++++++++++++++++++
 3 files changed, 1303 insertions(+)
 create mode 100644 drivers/media/i2c/ar0234.c
drivers/media/i2c/Kconfig +12 -0
index 5c52007f9cbe..febab9857cd5 100644
@@ -51,6 +51,18 @@ config VIDEO_ALVIUM_CSI2
 	  To compile this driver as a module, choose M here: the
 	  module will be called alvium-csi2.
 
+config VIDEO_AR0234
+	tristate "onsemi AR0234 sensor support"
+	depends on ACPI || OF || COMPILE_TEST
+	select V4L2_CCI_I2C
+	select VIDEO_CCS_PLL
+	help
+	  This is a Video4Linux2 sensor driver for the onsemi
+	  AR0234 camera.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ar0234.
+
 config VIDEO_AR0521
 	tristate "ON Semiconductor AR0521 sensor support"
 	help
drivers/media/i2c/Makefile +1 -0
index d04bd5724552..8310db5c63b5 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_VIDEO_AK7375) += ak7375.o
 obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
 obj-$(CONFIG_VIDEO_ALVIUM_CSI2) += alvium-csi2.o
 obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
+obj-$(CONFIG_VIDEO_AR0234) += ar0234.o
 obj-$(CONFIG_VIDEO_AR0521) += ar0521.o
 obj-$(CONFIG_VIDEO_BT819) += bt819.o
 obj-$(CONFIG_VIDEO_BT856) += bt856.o
drivers/media/i2c/ar0234.c new file +1290 -0

1,290 lines not on this page · raw message

Signature · 1 line
2.52.0
#5 lore raw

Re: [PATCH v2 2/2] media: i2c: Add onsemi AR0234 image sensor driver

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] Incorrect initialization order of the V4L2 active state and control handler breaks lock sharing…

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Incorrect initialization order of the V4L2 active state and control handler breaks lock sharing, causing lockdep splats, data races, and masking a self-deadlock in ar0234_set_pad_format().
- [High] Brittle and restrictive parsing of the 'link-frequencies' device tree property.
- [High] Invalid rectangle clamping logic in ar0234_set_selection() allows crop width and height to underflow their minimum limits.
- [High] Incorrect power-down sequence disables regulators before stopping the external clock.
- [Medium] Unchecked return value from v4l2_subdev_state_get_format() in ar0234_get_frame_desc() may cause a NULL pointer dereference.
- [Medium] Unconditional overwrite of the VBLANK control value upon format or crop changes.
- [Medium] Missing media_entity_cleanup() in the subdevice cleanup routine causes media graph objects to leak upon removal.
--

--- Patch [2]: [PATCH v2 2/2] media: i2c: Add onsemi AR0234 image sensor driver --- commit 2059817c01680d1d154e2e8a6d9f7a79bbf02ecf
Author: Alexander Shiyan <[email protected]>

media: i2c: Add onsemi AR0234 image sensor driver

Add driver for the onsemi AR0234 CMOS image sensor.

Quoted 6 lines
drivers/media/i2c/ar0234.c new file +0 -0
new file mode 100644
index 0000000000000..823cff01fb586
@@ -0,0 +1,1290 @@

[ ... ]

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +4 -0
+static int ar0234_set_pad_format(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_state *state,
+				 struct v4l2_subdev_format *fmt)
+{

[ ... ]

drivers/media/i2c/ar0234.c line 578

Quoted 9 lines
drivers/media/i2c/ar0234.c new file +9 -0
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+		int ret = ar0234_calculate_pll(ar0234, mode);
+
+		if (ret) {
+			dev_err(sd->dev, "PLL recalculation failed: %d\n", ret);
+			return -EINVAL;
+		}
+
+		mutex_lock(ar0234->ctrls.lock);

[Severity: High]
Will this cause a recursive self-deadlock once the state lock is properly unified with the control handler? The V4L2 core invokes this operation with the active state lock held. Calling mutex_lock() directly on the control lock here would block forever if they are correctly unified as the same lock.

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +4 -0
+		ar0234_set_link_limits(ar0234, mode);
+		ar0234_set_framing_limits(ar0234, crop->width);
+		mutex_unlock(ar0234->ctrls.lock);
+	}

[ ... ]

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +4 -0
+static int ar0234_set_selection(struct v4l2_subdev *sd,
+				struct v4l2_subdev_state *state,
+				struct v4l2_subdev_selection *sel)
+{

[ ... ]

drivers/media/i2c/ar0234.c line 659

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +4 -0
+	rect.width =
+		clamp_t(u32, rect.width, AR0234_MIN_CROP_WIDTH,
+			AR0234_PIXEL_ARRAY_LEFT + AR0234_PIXEL_ARRAY_WIDTH -
+			rect.left);

[Severity: High]
Can this logic allow the crop dimensions to underflow their minimum limits? If a userspace application requests a crop width of 0 and a large left offset, rect.left is pushed to the maximum allowed edge. The final clamp_t for rect.width evaluates with a lower bound (AR0234_MIN_CROP_WIDTH) that is greater than the calculated upper bound. Because clamp_t behaves as min(max(val, lo), hi), evaluating a clamp where lo > hi results in an underflow to the upper bound (e.g. 0), bypassing the minimum crop width and potentially programming invalid addresses into the sensor hardware.

Quoted 4 lines
drivers/media/i2c/ar0234.c new file +4 -0
+	rect.height =
+		clamp_t(u32, rect.height, AR0234_MIN_CROP_HEIGHT,
+			AR0234_PIXEL_ARRAY_TOP + AR0234_PIXEL_ARRAY_HEIGHT -
+			rect.top);

[ ... ]

drivers/media/i2c/ar0234.c line 535

Quoted 6 lines
drivers/media/i2c/ar0234.c new file +6 -0
+static void ar0234_set_framing_limits(struct ar0234 *ar0234, u32 width)
+{
+	int hblank =
+		max(AR0234_LINE_LENGTH_PCK_MIN * 4 - width, AR0234_HBLANK_MIN);
+
+	__v4l2_ctrl_s_ctrl(ar0234->vblank, AR0234_VBLANK_MIN);

[Severity: Medium]
Does this unintentionally destroy the userspace frame rate configuration? By unconditionally executing __v4l2_ctrl_s_ctrl() to set the control to AR0234_VBLANK_MIN, any application calling VIDIOC_SUBDEV_S_FMT or VIDIOC_SUBDEV_S_SELECTION will silently lose its configured vblank value. Could __v4l2_ctrl_modify_range() be used here instead to gracefully adjust the limits without overwriting the current value if it falls within the new range?

Quoted 6 lines
drivers/media/i2c/ar0234.c new file +6 -0
+
+	ar0234_update_exposure_limits(ar0234);
+
+	__v4l2_ctrl_modify_range(ar0234->hblank, AR0234_HBLANK_MIN,
+				 AR0234_HBLANK_MAX, 4, hblank);
+}

[ ... ]

drivers/media/i2c/ar0234.c line 828

Quoted 12 lines
drivers/media/i2c/ar0234.c new file +12 -0
+static int ar0234_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
+				 struct v4l2_mbus_frame_desc *fd)
+{
+	struct ar0234 *ar0234 = to_ar0234(sd);
+	const struct v4l2_mbus_framefmt *fmt;
+	struct v4l2_subdev_state *state;
+	const struct ar0234_mode *mode;
+	u32 code;
+
+	state = v4l2_subdev_lock_and_get_active_state(&ar0234->sd);
+	fmt = v4l2_subdev_state_get_format(state, pad);
+	code = fmt->code;

[Severity: Medium]
Is a NULL check required here for the return value of v4l2_subdev_state_get_format()? If an in-kernel caller or media controller path passes an invalid pad index (e.g., pad >= 1), the state format lookup will return NULL, leading to a crash when dereferencing fmt->code.

Quoted 1 line
drivers/media/i2c/ar0234.c new file +1 -0
+	v4l2_subdev_unlock_state(state);

[ ... ]

Quoted 2 lines
drivers/media/i2c/ar0234.c new file +2 -0
+static int ar0234_parse_hw_config(struct ar0234 *ar0234)
+{

[ ... ]

drivers/media/i2c/ar0234.c line 1020

Quoted 1 line
drivers/media/i2c/ar0234.c new file +1 -0
+	if (ep_cfg->nr_of_link_frequencies != AR0234_LINK_FREQ_IDX_MAX) {

[Severity: High]
Is it too restrictive to demand exactly AR0234_LINK_FREQ_IDX_MAX (2) link frequencies in the device tree? If a board only supports one link frequency (for instance, only 10bpp is possible), or lists them in a different order, this check will cause the driver to fail probing. Could this be made more flexible to better accommodate standard device tree semantics?

Quoted 5 lines
drivers/media/i2c/ar0234.c new file +5 -0
+		ret = dev_err_probe(ar0234->sd.dev, -EINVAL,
+				    "Invalid number of link frequencies %u\n",
+				    ep_cfg->nr_of_link_frequencies);
+		goto done_endpoint_free;
+	}

[ ... ]

drivers/media/i2c/ar0234.c line 1127

Quoted 10 lines
drivers/media/i2c/ar0234.c new file +10 -0
+static int ar0234_power_off(struct device *dev)
+{
+	struct v4l2_subdev *sd = dev_get_drvdata(dev);
+	struct ar0234 *ar0234 = to_ar0234(sd);
+
+	gpiod_set_value_cansleep(ar0234->reset, 1);
+
+	regulator_bulk_disable(ARRAY_SIZE(ar0234->supplies), ar0234->supplies);
+
+	clk_disable_unprepare(ar0234->clk);

[Severity: High]
Does disabling the regulators before stopping the external clock risk hardware damage? Disabling power to the sensor while an external clock continues to toggle its pins can backpower the chip through its internal ESD protection diodes. Should clk_disable_unprepare() be called before regulator_bulk_disable()?

drivers/media/i2c/ar0234.c line 1139

Quoted 12 lines
drivers/media/i2c/ar0234.c new file +12 -0
+
+	/* 100ms PwrDown until next PwrUp */
+	fsleep(100000);
+
+	return 0;
+}
+
+static void ar0234_subdev_cleanup(struct ar0234 *ar0234)
+{
+	v4l2_subdev_cleanup(&ar0234->sd);
+	v4l2_ctrl_handler_free(&ar0234->ctrls);
+}

[Severity: Medium]
Does this subdevice cleanup sequence leak media graph objects? The driver initializes the media entity pads in ar0234_probe() via media_entity_pads_init(), but appears to be missing a corresponding call to media_entity_cleanup() here. This would leak dynamically allocated graph resources every time the driver is unbound or during a late probe failure.

[ ... ]

Quoted 2 lines
drivers/media/i2c/ar0234.c new file +2 -0
+static int ar0234_probe(struct i2c_client *client)
+{

[ ... ]

drivers/media/i2c/ar0234.c line 1217

Quoted 9 lines
drivers/media/i2c/ar0234.c new file +9 -0
+	ret = v4l2_subdev_init_finalize(&ar0234->sd);
+	if (ret)
+		goto error_pm;
+
+	ret = ar0234_ctrls_init(ar0234);
+	if (ret)
+		goto error_pm;
+
+	ar0234->sd.state_lock = ar0234->ctrls.lock;

[Severity: High]
Does initializing the active state before assigning the state_lock break the lock sharing mechanism?

Because v4l2_subdev_init_finalize() is called before sd->state_lock is assigned to ar0234->ctrls.lock, the V4L2 core allocates a separate mutex for the active state instead of sharing the control handler's lock.

This causes v4l2_subdev_get_locked_active_state() to trigger a lockdep splat in ar0234_set_ctrl() because the required state->lock is not held, and it leaves state modifications unprotected.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2