Re: [PATCH 0/3] media: v4l: async: add helper API v4l2_async_pad_init_and_register_subdev()

From: Michael Riesch

Date: Mon Feb 23 2026 - 03:36:11 EST


Hi Frank,

On 2/20/26 16:46, Frank Li wrote:
> On Fri, Feb 20, 2026 at 10:01:01AM +0100, Michael Riesch wrote:
>> Hi Frank,
>>
>> Thanks for your patches.
>>
>> On 2/10/26 22:42, Frank Li wrote:
>>> Add the helper API v4l2_async_pad_init_and_register_subdev(), which
>>> combines media_entity_pads_init(), v4l2_subdev_init_finalize(), and
>>> v4l2_async_register_subdev() into a single call.
>>
>> I think this is a good idea, but can you extend that to offer variants
>> for v4l2_async_register_subdev_sensor and v4l2_device_register_subdev too?
>>
>> The function names are awfully long, though. Can we call this
>> media_register_subdev{_async,_sensor,}
>> maybe?
>
> How about media_async_register_subdev()? which basic align other API
> naming. I want to add more helper APIs.

This would work for me.

> drivers/media/platform/synopsys/dw-mipi-csi2rx.c have about 600 lines code
> but related hardware register codes are below 20 line, only few registers.
>
> I just post this simple version to gather feedback from maintainers and
> reviewers on the overall approach.

Sure, that's reasonable.

Just saying that if you plan to provide more helpers, there may be a
smart way to do so without copying the new helper function code three
times. Maybe

int helper(struct v4l2_subdev* sd, u16 num_pads, struct media_pad *pads,
struct module *module,
int (*cb)(struct v4l2_subdev *, struct module *))

and

#define media_async_register_subdev(sd, num_pads, pads) \
helper(sd, num_pads, pads, THIS_MODULE,
__v4l2_async_register_subdev)

or so?

Best regards,
Michael

>
> Frank
>
>>
>> Best regards,
>> Michael
>>
>>>
>>> Reduce code duplication and simplify error handling in drivers.
>>>
>>> Only change dwc and cdns. If agree add API, more driver can be simplified.
>>>
>>> Signed-off-by: Frank Li <Frank.Li@xxxxxxx>
>>> ---
>>> Frank Li (3):
>>> media: v4l: async: add helper API v4l2_async_pad_init_and_register_subdev()
>>> media: synopsys: Use v4l2_async_pad_init_and_register_subdev() to simplify code
>>> media: cadence: cdns-csi2rx: Use v4l2_async_pad_init_and_register_subdev() to simplify code
>>>
>>> drivers/media/platform/cadence/cdns-csi2rx.c | 18 ++++----------
>>> drivers/media/platform/synopsys/dw-mipi-csi2rx.c | 15 +++---------
>>> drivers/media/v4l2-core/v4l2-async.c | 30 ++++++++++++++++++++++++
>>> include/media/v4l2-async.h | 18 ++++++++++++++
>>> 4 files changed, 55 insertions(+), 26 deletions(-)
>>> ---
>>> base-commit: bc0bfce7d0f8204e0bbadcee72e87ad9ec105c73
>>> change-id: 20260210-v4l2_init_register-0e6d0adcfa21
>>>
>>> Best regards,
>>> --
>>> Frank Li <Frank.Li@xxxxxxx>
>>>
>>