Re: [PATCH v2 5/9] media: i2c: ov7251: Use sub-device active state
From: Andy Shevchenko
Date: Thu Oct 29 2026 - 10:05:45 EST
On Wed, Oct 28, 2026 at 08:21:50PM +0900, Antoine Pichot wrote:
> Port the ov7251 driver to the sub-device active state.
>
> The driver kept its own copies of the active format and crop rectangle
> and selected between them and the try state with a pair of helpers
> switching on the format's "which" field. Move the format and the crop
> rectangle to the sub-device state for both the try and the active case,
> drop the helpers and the private copies, and use the v4l2_subdev_get_fmt
> helper for get_fmt. The init_state operation now fills whichever state
> it is given through set_fmt, so the explicit ov7251_init_state() call at
> the end of probe goes away; the exposure control gets the default mode's
> range at creation instead of being adjusted by that call.
>
> The driver mutex went away with it. The control handler's own lock now
> serves as the state lock as well, so the control framework and the
> sub-device core serialise the pad operations, the control operations
> and the stream start between them; s_stream takes the active state lock
> itself. The mode pointer, which the frame interval operations still
> select by frame rate, stays and is protected by the same lock.
>
> Behaviour is unchanged for applications. As a side effect the core now
> reports V4L2_SUBDEV_FL_HAS_EVENTS for the sub-device and handles control
> event subscription, so v4l2-compliance's VIDIOC_(UN)SUBSCRIBE_EVENT test
> passes without the driver having to declare the event operations.
...
> - mutex_lock(&ov7251->lock);
> + state = v4l2_subdev_lock_and_get_active_state(subdev);
>
> if (enable) {
> ret = pm_runtime_resume_and_get(ov7251->dev);
> if (ret) {
> - mutex_unlock(&ov7251->lock);
> + v4l2_subdev_unlock_state(state);
> return ret;
> }
> pm_runtime_put(ov7251->dev);
> }
>
> - mutex_unlock(&ov7251->lock);
> + v4l2_subdev_unlock_state(state);
> return ret;
>
> err_power_down:
> pm_runtime_put(ov7251->dev);
> - mutex_unlock(&ov7251->lock);
> + v4l2_subdev_unlock_state(state);
> return ret;
I'm wondering if v4l2 provides the set of conditional guards and hence some
kind of ACQUIRE() macro.
--
With Best Regards,
Andy Shevchenko