Add a devm-managed version of v4l2_async_register_subdev_sensor() to
simplify sensor sub-device registration and cleanup using devres.
Signed-off-by: Tarang Raval <tarang.raval@siliconsignals.io>
---
drivers/media/v4l2-core/v4l2-async.c | 19 +++++++++++++++++++
include/media/v4l2-async.h | 18 ++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index ee884a8221fb..197a01a2d5d6 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -7,6 +7,7 @@
#include <linux/debugfs.h>
#include <linux/device.h>
+#include <linux/device/devres.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/list.h>
@@ -894,6 +895,24 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
}
EXPORT_SYMBOL(v4l2_async_unregister_subdev);
+static void devm_v4l2_async_unregister_subdev(void *data)
+{
+ v4l2_async_unregister_subdev(data);
+}
+
+int devm_v4l2_async_register_subdev_sensor(struct device *dev,
+ struct v4l2_subdev *sd)
+{
+ int err;
+
+ err = v4l2_async_register_subdev_sensor(sd);
+ if (err)
+ return err;
+
+ return devm_add_action_or_reset(dev, devm_v4l2_async_unregister_subdev, sd);
+};
+EXPORT_SYMBOL(devm_v4l2_async_register_subdev_sensor);
+
static void print_waiting_match(struct seq_file *s,
struct v4l2_async_match_desc *match)
{
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index f26c323e9c96..df0e7337fd22 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -343,4 +343,22 @@ v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd);
* @sd: pointer to &struct v4l2_subdev
*/
void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
+
+/**
+ * devm_v4l2_async_register_subdev_sensor - Managed registration of V4L2 sensor sub-device
+ *
+ * @dev: Device that manages the lifecycle of the V4L2 sub-device.
+ * @sd: V4L2 sub-device to be registered as a sensor.
+ *
+ * This function registers a V4L2 sub-device using the asynchronous sub-device
+ * framework and registers a managed cleanup action to be performed automatically
+ * when the device is detached or the driver is unloaded.
+ *
+ * This is a managed version of v4l2_async_register_subdev_sensor(), and simplifies
+ * resource management using devres.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int devm_v4l2_async_register_subdev_sensor(struct device *dev,
+ struct v4l2_subdev *sd);
#endif
--
2.34.1
Hi Tarang, kernel test robot noticed the following build errors: [auto build test ERROR on sailus-media-tree/master] [also build test ERROR on linus/master v6.16-rc7 next-20250724] [cannot apply to sailus-media-tree/streams] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Tarang-Raval/media-mc-Add-devm_media_entity_pads_init-helper/20250723-182930 base: git://linuxtv.org/sailus/media_tree.git master patch link: https://lore.kernel.org/r/20250723102515.64585-3-tarang.raval%40siliconsignals.io patch subject: [PATCH 2/4] media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper config: hexagon-randconfig-002-20250725 (https://download.01.org/0day-ci/archive/20250725/202507250804.YlLveyKO-lkp@intel.com/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 853c343b45b3e83cc5eeef5a52fc8cc9d8a09252) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250725/202507250804.YlLveyKO-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202507250804.YlLveyKO-lkp@intel.com/ All errors (new ones prefixed by >>, old ones prefixed by <<): >> ERROR: modpost: "v4l2_async_register_subdev_sensor" [drivers/media/v4l2-core/v4l2-async.ko] undefined! -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.