Linux Media Controller development
 help / color / mirror / Atom feed
From: Frank Li <Frank.Li@nxp.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Michael Riesch <michael.riesch@collabora.com>,
	 Maxime Ripard <mripard@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	 imx@lists.linux.dev, Frank Li <Frank.Li@nxp.com>
Subject: [PATCH v2 1/3] media: v4l: async: add helper API media_async_register_subdev()
Date: Thu, 26 Feb 2026 17:55:26 -0500	[thread overview]
Message-ID: <20260226-v4l2_init_register-v2-1-902d7140f9fa@nxp.com> (raw)
In-Reply-To: <20260226-v4l2_init_register-v2-0-902d7140f9fa@nxp.com>

Add the helper API media_async_register_subdev(), which
combines media_entity_pads_init(), v4l2_subdev_init_finalize(), and
v4l2_async_register_subdev() into a single call.

Reduce code duplication and simplify error handling in drivers.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/media/v4l2-core/v4l2-async.c | 33 +++++++++++++++++++++++++++++++++
 include/media/v4l2-async.h           | 22 ++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index 1c08bba9ecb91f46b7479da613d6c1688d4b0b5c..e07173f566fbd8fa332b5e58be288e806b4c0482 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 
+#include <media/media-entity.h>
 #include <media/v4l2-async.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-fwnode.h>
@@ -881,6 +882,38 @@ int __v4l2_async_register_subdev(struct v4l2_subdev *sd, struct module *module)
 }
 EXPORT_SYMBOL(__v4l2_async_register_subdev);
 
+int __media_pad_init_and_register_subdev(struct v4l2_subdev *sd, u16 num_pads,
+	struct media_pad *pads,
+	int (*register_subdev)(struct v4l2_subdev *sd, struct module *module),
+	struct module *module)
+{
+	int ret;
+
+	if (!register_subdev)
+		return -EINVAL;
+
+	ret = media_entity_pads_init(&sd->entity, num_pads, pads);
+	if (ret)
+		return ret;
+
+	ret = v4l2_subdev_init_finalize(sd);
+	if (ret)
+		goto err_entity_cleanup;
+
+	ret = register_subdev(sd, module);
+	if (ret)
+		goto err_subdev_cleanup;
+
+	return 0;
+
+err_subdev_cleanup:
+	v4l2_subdev_cleanup(sd);
+err_entity_cleanup:
+	media_entity_cleanup(&sd->entity);
+	return ret;
+}
+EXPORT_SYMBOL(__media_pad_init_and_register_subdev);
+
 void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 {
 	struct v4l2_async_connection *asc, *asc_tmp;
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index f26c323e9c963065fd7c19d6d9835df1194bc069..220a302a626732e15452f3efb19b03bdc51e64d5 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -336,6 +336,28 @@ int __v4l2_async_register_subdev(struct v4l2_subdev *sd, struct module *module);
 int __must_check
 v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd);
 
+struct media_pad;
+
+int __must_check
+__media_pad_init_and_register_subdev(struct v4l2_subdev *sd, u16 num_pads,
+	struct media_pad *pads,
+	int (*register_subdev)(struct v4l2_subdev *sd, struct module *module),
+	struct module *module);
+
+/**
+ * media_async_register_subdev - Initialize the entity pads and
+ *				 registers a sub-device to the
+ *				 asynchronous subdevice framework
+ * @sd: pointer to &struct v4l2_subdev
+ * @num_pads: total number of sink and source pads
+ * @pads: Array of @num_pads pads.
+ *
+ * Returns an error on failure, 0 on success.
+ */
+#define media_async_register_subdev(sd, num_pads, pads)			\
+	__media_pad_init_and_register_subdev(sd, num_pads, pads,	\
+					     __v4l2_async_register_subdev, \
+					     THIS_MODULE)
 /**
  * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
  *	subdevice framework

-- 
2.43.0


  reply	other threads:[~2026-02-26 22:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26 22:55 [PATCH v2 0/3] media: v4l: async: add helper API v4l2_async_pad_init_and_register_subdev() Frank Li
2026-02-26 22:55 ` Frank Li [this message]
2026-03-02 13:21   ` [PATCH v2 1/3] media: v4l: async: add helper API media_async_register_subdev() Sakari Ailus
2026-03-02 15:43     ` Frank Li
2026-03-04 22:04       ` Frank Li
2026-02-26 22:55 ` [PATCH v2 2/3] media: synopsys: Use media_async_register_subdev() to simplify code Frank Li
2026-02-26 22:55 ` [PATCH v2 3/3] media: cadence: cdns-csi2rx: " Frank Li

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=20260226-v4l2_init_register-v2-1-902d7140f9fa@nxp.com \
    --to=frank.li@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=michael.riesch@collabora.com \
    --cc=mripard@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /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