media: i2c: Add onsemi AR0234 camera sensor driver
Subsystems (3)
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 RK3568 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: 0x0000000000000002interval-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
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 | 123 ++ drivers/media/i2c/Kconfig | 12 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ar0234.c | 1265 +++++++++++++++++ 4 files changed, 1401 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
PATCH 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 | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +123 -0
@@ -0,0 +1,123 @@ +# 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 (must be 2 or 4) + minItems: 2 + maxItems: 4 + items: + enum: [1, 2, 3, 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 = <®_cam_vaa>; + vdd-supply = <®_cam_vdd>; + vddio-supply = <®_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
[email protected]
AI reviewRe: [PATCH 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The `compatible` property schema contains fatal YAML syntax errors due to missing list hyphens…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [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. --
--- Patch [1]: [PATCH 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding --- commit 883339f4cdfd1f0ac858633345ef05f216a1e0e8
Author: Alexander Shiyan <[email protected]>
dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding
This commit adds a new devicetree binding schema for the onsemi AR0234 CMOS image sensor. It details properties for compatible strings, clocks, supplies, and the MIPI CSI-2 port configurations.
Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 26
Quoted 9 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +9
-0+properties: + compatible: + oneOf: + const: onnn,ar0234cs + items: + enum: + onnn,ar0234cssc + onnn,ar0234cssm + const: onnn,ar0234cs
[Severity: Low]
Are hyphens missing for the array elements in this compatible block?
Without list hyphens under oneOf, items, and enum, the YAML parser might treat these as mappings or multi-line scalar strings instead of valid JSON schema array constructs. This invalid structure will cause dt_binding_check to fail.
[ ... ]
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml line 64
Quoted 8 lines
Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml new file +8
-0+ endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + properties: + data-lanes: + description: Number of MIPI CSI-2 data lanes (must be 2 or 4) + minItems: 2 + maxItems: 4
[Severity: Low]
Does this constraint mathematically permit 3 data lanes, contradicting the description that the hardware must use exactly 2 or 4 lanes?
A device tree specifying data-lanes = <1 2 3> would silently pass validation. Could this be structured using a oneOf block with exact limits to strictly enforce the hardware requirement?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Rob Herring (Arm)
maintainerRe: [PATCH 1/2] dt-bindings: media: i2c: Add onsemi AR0234 image sensor binding
In reply to Alexander ShiyanQuoted 8 lines · Alexander Shiyan
Add devicetree binding for the onsemi AR0234 CMOS image sensor.
Signed-off-by Alexander Shiyan <[email protected]>--- .../bindings/media/i2c/onnn,ar0234.yaml | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml: ignoring, error in schema: properties: compatible: oneOf
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml: properties:compatible:oneOf: {'const': 'onnn,ar0234cs', 'items': {'enum': 'onnn,ar0234cssc onnn,ar0234cssm', 'const': 'onnn,ar0234cs'}} should not be valid under {'items': {'propertyNames': {'const': 'const'}, 'required': ['const']}}
hint: Use 'enum' rather than 'oneOf' + 'const' entries
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml: properties:compatible:oneOf: {'const': 'onnn,ar0234cs', 'items': {'enum': 'onnn,ar0234cssc onnn,ar0234cssm', 'const': 'onnn,ar0234cs'}} is not of type 'array'
from schema $id: http://devicetree.org/meta-schemas/string-array.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/media/i2c/onnn,ar0234.yaml: properties:compatible:oneOf: {'const': 'onnn,ar0234cs', 'items': {'enum': 'onnn,ar0234cssc onnn,ar0234cssm', 'const': 'onnn,ar0234cs'}} is not of type 'array'
Traceback (most recent call last):
File "/usr/local/bin/dt-doc-validate", line 8, in <module>
sys.exit(main())
~~~~^^
File "/usr/local/lib/python3.13/dist-packages/dtschema/doc_validate.py", line 66, in main
ret |= check_doc(f)
~~~~~~~~~^^^
File "/usr/local/lib/python3.13/dist-packages/dtschema/doc_validate.py", line 37, in check_doc
dtsch.check_schema_refs()
~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/local/lib/python3.13/dist-packages/dtschema/schema.py", line 242, in check_schema_refs
self._check_schema_refs(resolver, self)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/dist-packages/dtschema/schema.py", line 212, in _check_schema_refs
self._check_schema_refs(resolver, v, parent=k, is_common=is_common,
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
has_constraint=has_constraint)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/dist-packages/dtschema/schema.py", line 212, in _check_schema_refs
self._check_schema_refs(resolver, v, parent=k, is_common=is_common,
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
has_constraint=has_constraint)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/dist-packages/dtschema/schema.py", line 203, in _check_schema_refs
ref_sch = resolver.lookup(schema['$ref']).contents
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 682, in lookup
retrieved = self._registry.get_or_retrieve(uri)
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 422, in get_or_retrieve
registry = self.crawl()
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 500, in crawl
id = resource.id()
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 231, in id
id = self._specification.id_of(self.contents)
File "/usr/local/lib/python3.13/dist-packages/referencing/jsonschema.py", line 50, in _dollar_id
return contents.get("$id")
^^^^^^^^^^^^AttributeError: 'str' object has no attribute 'get'Documentation/devicetree/bindings/media/i2c/onnn,ar0234.example.dtb: /example-0/i2c/camera@18: failed to match any schema with compatible: ['onnn,ar0234cssc', 'onnn,ar0234cs'] Documentation/devicetree/bindings/media/i2c/onnn,ar0234.example.dtb: /example-0/i2c/camera@18: failed to match any schema with compatible: ['onnn,ar0234cssc', 'onnn,ar0234cs']
doc reference errors (make refcheckdocs):
See https://patchwork.kernel.org/project/devicetree/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
PATCH 2/2 media: i2c: Add onsemi AR0234 image sensor driver
In reply to Alexander ShiyanAdd driver for the onsemi AR0234 CMOS image sensor.
--- drivers/media/i2c/Kconfig | 12 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ar0234.c | 1265 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1278 insertions(+) create mode 100644 drivers/media/i2c/ar0234.c
drivers/media/i2c/Kconfig +12 -0
@@ -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
@@ -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 +1265 -0
1,265 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH 2/2] media: i2c: Add onsemi AR0234 image sensor driver
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider: - [Critical] Incorrect clamping order in crop selection bounds calculation causes unsigned integer…
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [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.
--
--- Patch [2]: [PATCH 2/2] media: i2c: Add onsemi AR0234 image sensor driver --- commit eb8d4f60c8466169ec68bf0a9f862a5fa52e97fd
Author: Alexander Shiyan <[email protected]>
Subject: media: i2c: Add onsemi AR0234 image sensor driver
This commit adds a new driver for the onsemi AR0234 CMOS image sensor.
drivers/media/i2c/ar0234.c new file +0 -0
@@ -0,0 +1,1265 @@
[ ... ]
Quoted 9 lines
static void
ar0234_set_framing_limits(struct ar0234 *ar0234, u32 width){ int hblank = AR0234_LINE_LENGTH_PCK_MIN * 4 - width; __v4l2_ctrl_s_ctrl(ar0234->vblank, AR0234_VBLANK_MIN); __v4l2_ctrl_modify_range(ar0234->hblank, AR0234_HBLANK_MIN, AR0234_HBLANK_MAX, 4, hblank); }
[Severity: High]
Could this allow the line length to be reduced below the hardware minimum?
If userspace reduces the format width and sets hblank to this static minimum, the resulting programmed line length might violate the hardware minimum requirement of 612. Should AR0234_HBLANK_MIN be calculated dynamically based on the current width?
[ ... ]
Quoted 4 lines
static int ar0234_set_pad_format(struct
v4l2_subdev*sd,
structv4l2_subdev_state*state, structv4l2_subdev_format*fmt)
{
[ ... ]
Quoted 9 lines
*v4l2_subdev_state_get_format(state, fmt->pad) = fmt->format;
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;
}[Severity: Medium]
Is it safe to write to the active format state before verifying that the PLL configuration is structurally possible?
If ar0234_calculate_pll() fails, it returns -EINVAL, but the active state has already been irreversibly modified and left inconsistent.
[ ... ]
Quoted 4 lines
static int ar0234_set_selection(struct
v4l2_subdev*sd,
structv4l2_subdev_state*state, structv4l2_subdev_selection*sel)
{
[ ... ]
Quoted 6 lines
/* Clamp the top-left corner so that the whole rectangle stays */ /* inside the active pixel array */ rect.left = clamp_t(u32, rect.left, AR0234_PIXEL_ARRAY_LEFT, AR0234_PIXEL_ARRAY_LEFT + AR0234_PIXEL_ARRAY_WIDTH - rect.width);
[Severity: Critical]
Can this bounds check underflow if a maliciously large rect.width is provided?
Subtracting an unvalidated width from the pixel array dimensions could result in a massive upper limit due to 32-bit unsigned arithmetic underflow, defeating the clamp for rect.left and causing subsequent clamps to fail as well.
[ ... ]
Quoted 8 lines
*crop = rect; sel->r = rect; if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) ar0234_set_framing_limits(ar0234, crop->width); return 0; }
[Severity: Medium]
Does changing the crop height require updating the exposure control limits?
ar0234_set_framing_limits() forces vblank to AR0234_VBLANK_MIN, but if vblank is already at its minimum, the V4L2 core skips the control setter. As a result, the exposure limit is never recalculated for the smaller crop height.
[ ... ]
Quoted 2 lines
static int
ar0234_set_ctrl(struct v4l2_ctrl *ctrl){
[ ... ]
Quoted 2 lines
if (!pm_runtime_get_if_active(sd->dev)) return 0;
[Severity: High]
Does this properly handle negative error codes from pm_runtime_get_if_active?
If runtime PM is disabled, it returns a negative error code (e.g., -EINVAL). Because it is non-zero, this check bypasses the early return, proceeds to access the hardware, and then calls pm_runtime_put_autosuspend(), which will underflow the usage counter since get never incremented it.
[ ... ]
Quoted 2 lines
static int
ar0234_ctrls_init(struct ar0234 *ar0234){
[ ... ]
Quoted 7 lines
ar0234->sd.ctrl_handler = &ar0234->ctrls; ar0234_set_link_limits(ar0234, &ar0234_modes[0]); ar0234_set_framing_limits(ar0234, AR0234_PIXEL_ARRAY_WIDTH); return 0; }
[Severity: Medium]
Could these calls trigger a lockdep warning during boot?
ar0234_set_link_limits() and ar0234_set_framing_limits() invoke unlocked internal control API functions which assert that the control handler lock is held. Since this happens during probe before the lock is explicitly acquired, this might cause a diagnostic splat.
[ ... ]
Quoted 4 lines
static int
ar0234_parse_hw_config(struct ar0234 *ar0234){ struct v4l2_fwnode_endpoint *ep_cfg = &ar0234->ep_cfg; struct fwnode_handle *ep __free(fwnode_handle) = NULL;
[ ... ]
Quoted 9 lines
switch (ep_cfg->bus.mipi_csi2.num_data_lanes) {
case 2:
case 4:
break;
default:
ret = dev_err_probe(ar0234->sd.dev, -EINVAL,
"Invalid number of CSI2 data lanes %d\n",
ep_cfg->bus.mipi_csi2.num_data_lanes);
goto done_endpoint_free;[Severity: Medium]
Is it acceptable to mix goto-based error labels with scope-based __free() cleanup in the same function?
According to the cleanup.h API guidelines, mixing these heavily obscures ownership semantics and makes the function susceptible to memory leaks and double-free bugs during future maintenance.
[ ... ]
Quoted 3 lines
static int ar0234_get_frame_desc(struct
v4l2_subdev*sd, unsigned int pad,
structv4l2_mbus_frame_desc*fd)
{
[ ... ]
Quoted 5 lines
state = v4l2_subdev_lock_and_get_active_state(&ar0234->sd); fmt = v4l2_subdev_state_get_format(state, pad); v4l2_subdev_unlock_state(state); mode = ar0234_mode_from_code(ar0234, fmt->code, true);
[Severity: Medium]
Is it safe to access fmt->code after releasing the active state lock?
The lock is dropped, so a concurrent set_fmt ioctl could potentially overwrite the format while it is being read here, leading to inconsistent reads.
[ ... ]
Quoted 2 lines
static int
ar0234_power_on(struct device *dev)
{
[ ... ]
Quoted 7 lines
gpiod_set_value_cansleep(ar0234->reset, 0); /* ~160000 EXTCLKs */ fsleep(DIV_ROUND_UP(160000ULL * 1000000, clk_get_rate(ar0234->clk))); return 0; }
[Severity: Low]
Can this cause a build failure on 32-bit architectures?
DIV_ROUND_UP with a 64-bit numerator expands to a 64-bit by 32-bit division using the / operator, which is prohibited in the kernel. Should this use DIV_ROUND_UP_ULL instead?
[Severity: High]
Also, what happens if clk_get_rate(ar0234->clk) returns 0?
Since the clock rate is used as a divisor without prior validation, a misconfigured clock could cause a kernel panic (division by zero) during driver probe.
[ ... ]
Quoted 5 lines
static void
ar0234_subdev_cleanup(struct ar0234 *ar0234){ media_entity_cleanup(&ar0234->sd.entity); v4l2_ctrl_handler_free(&ar0234->ctrls); }
[Severity: High]
Does this leak the active subdevice state?
The V4L2 active state is allocated by v4l2_subdev_init_finalize() during probe, but it appears v4l2_subdev_cleanup() is never called to free it during teardown, leading to a permanent leak on every unbind or failed probe.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2