* [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems
@ 2025-07-23 10:25 Tarang Raval
2025-07-23 10:25 ` [PATCH 1/4] media: mc: Add devm_media_entity_pads_init() helper Tarang Raval
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Tarang Raval @ 2025-07-23 10:25 UTC (permalink / raw)
To: sakari.ailus, laurent.pinchart, hverkuil
Cc: Tarang Raval, Mauro Carvalho Chehab, Ricardo Ribalda,
Hans de Goede, James Cowgill, Yunke Cao, Tomi Valkeinen,
Lad Prabhakar, Tommaso Merciai, linux-media, linux-kernel
This patch series introduces devm-managed versions of several commonly used
media and V4L2 initialization functions. These helpers simplify resource
management by leveraging the devres infrastructure, ensuring automatic
cleanup when the associated device is detached or the driver is unloaded.
Tested with IMX219 and OV2735 camera sensors on an i.MX8MP-based platform.
Tarang Raval (4):
media: mc: Add devm_media_entity_pads_init() helper
media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper
media: v4l2: subdev: Add devm_v4l2_subdev_init_finalize() helper
media: v4l2-ctrls: Add devm_v4l2_ctrl_handler_init() helper
drivers/media/mc/mc-entity.c | 19 +++++++++++++++++++
drivers/media/v4l2-core/v4l2-async.c | 19 +++++++++++++++++++
drivers/media/v4l2-core/v4l2-ctrls-core.c | 20 ++++++++++++++++++++
drivers/media/v4l2-core/v4l2-subdev.c | 18 ++++++++++++++++++
include/media/media-entity.h | 20 ++++++++++++++++++++
include/media/v4l2-async.h | 18 ++++++++++++++++++
include/media/v4l2-ctrls.h | 19 +++++++++++++++++++
include/media/v4l2-subdev.h | 17 +++++++++++++++++
8 files changed, 150 insertions(+)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/4] media: mc: Add devm_media_entity_pads_init() helper
2025-07-23 10:25 [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Tarang Raval
@ 2025-07-23 10:25 ` Tarang Raval
2025-07-23 10:25 ` [PATCH 2/4] media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper Tarang Raval
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Tarang Raval @ 2025-07-23 10:25 UTC (permalink / raw)
To: sakari.ailus, laurent.pinchart, hverkuil
Cc: Tarang Raval, Mauro Carvalho Chehab, Ricardo Ribalda, Yunke Cao,
Hans de Goede, James Cowgill, Tomi Valkeinen, Lad Prabhakar,
Tommaso Merciai, linux-media, linux-kernel
Add a devm-managed version of media_entity_pads_init() to simplify
pad initialization and cleanup using devres.
Signed-off-by: Tarang Raval <tarang.raval@siliconsignals.io>
---
drivers/media/mc/mc-entity.c | 19 +++++++++++++++++++
include/media/media-entity.h | 20 ++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
index 045590905582..fe50da3faf08 100644
--- a/drivers/media/mc/mc-entity.c
+++ b/drivers/media/mc/mc-entity.c
@@ -8,6 +8,7 @@
* Sakari Ailus <sakari.ailus@iki.fi>
*/
+#include <linux/device/devres.h>
#include <linux/bitmap.h>
#include <linux/list.h>
#include <linux/property.h>
@@ -235,6 +236,24 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
}
EXPORT_SYMBOL_GPL(media_entity_pads_init);
+static void devm_media_entity_cleanup(void *data)
+{
+ media_entity_cleanup(data);
+}
+
+int devm_media_entity_pads_init(struct device *dev, struct media_entity *entity,
+ u16 num_pads, struct media_pad *pads)
+{
+ int err;
+
+ err = media_entity_pads_init(entity, num_pads, pads);
+ if (err)
+ return err;
+
+ return devm_add_action_or_reset(dev, devm_media_entity_cleanup, entity);
+}
+EXPORT_SYMBOL_GPL(devm_media_entity_pads_init);
+
/* -----------------------------------------------------------------------------
* Graph traversal
*/
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 64cf590b1134..28b904fe34ae 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -717,6 +717,26 @@ void media_gobj_destroy(struct media_gobj *gobj);
int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
struct media_pad *pads);
+/**
+ * devm_media_entity_pads_init - Managed initialization of media entity pads
+ *
+ * @dev: Device that manages the lifecycle of the media entity.
+ * @entity: Entity where the pads belong.
+ * @num_pads: Total number of sink and source pads.
+ * @pads: Array of @num_pads pads.
+ *
+ * This function initializes the pads for the given media entity 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 media_entity_pads_init(), and simplifies resource
+ * management using devres.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int devm_media_entity_pads_init(struct device *dev, struct media_entity *entity,
+ u16 num_pads, struct media_pad *pads);
+
/**
* media_entity_cleanup() - free resources associated with an entity
*
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/4] media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper
2025-07-23 10:25 [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Tarang Raval
2025-07-23 10:25 ` [PATCH 1/4] media: mc: Add devm_media_entity_pads_init() helper Tarang Raval
@ 2025-07-23 10:25 ` Tarang Raval
2025-07-25 0:13 ` kernel test robot
2025-07-23 10:25 ` [PATCH 3/4] media: v4l2-subdev: Add devm_v4l2_subdev_init_finalize() helper Tarang Raval
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Tarang Raval @ 2025-07-23 10:25 UTC (permalink / raw)
To: sakari.ailus, laurent.pinchart, hverkuil
Cc: Tarang Raval, Mauro Carvalho Chehab, Ricardo Ribalda,
Hans de Goede, Yunke Cao, James Cowgill, Tomi Valkeinen,
Lad Prabhakar, Tommaso Merciai, linux-media, linux-kernel
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/4] media: v4l2-subdev: Add devm_v4l2_subdev_init_finalize() helper
2025-07-23 10:25 [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Tarang Raval
2025-07-23 10:25 ` [PATCH 1/4] media: mc: Add devm_media_entity_pads_init() helper Tarang Raval
2025-07-23 10:25 ` [PATCH 2/4] media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper Tarang Raval
@ 2025-07-23 10:25 ` Tarang Raval
2025-07-23 10:25 ` [PATCH 4/4] media: v4l2-ctrls: Add devm_v4l2_ctrl_handler_init() helper Tarang Raval
2025-07-23 12:55 ` [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Laurent Pinchart
4 siblings, 0 replies; 10+ messages in thread
From: Tarang Raval @ 2025-07-23 10:25 UTC (permalink / raw)
To: sakari.ailus, laurent.pinchart, hverkuil
Cc: Tarang Raval, Mauro Carvalho Chehab, Ricardo Ribalda, Yunke Cao,
James Cowgill, Tomi Valkeinen, Lad Prabhakar, Tommaso Merciai,
linux-media, linux-kernel
Add a devm-managed version of v4l2_subdev_init_finalize() to simplify
sub-device finalization and cleanup using devres.
Signed-off-by: Tarang Raval <tarang.raval@siliconsignals.io>
---
drivers/media/v4l2-core/v4l2-subdev.c | 18 ++++++++++++++++++
include/media/v4l2-subdev.h | 17 +++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index c69d1aff701f..da7a479584bc 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -8,6 +8,7 @@
* Sakari Ailus <sakari.ailus@iki.fi>
*/
+#include <linux/device/devres.h>
#include <linux/export.h>
#include <linux/ioctl.h>
#include <linux/leds.h>
@@ -1710,6 +1711,23 @@ void v4l2_subdev_cleanup(struct v4l2_subdev *sd)
}
EXPORT_SYMBOL_GPL(v4l2_subdev_cleanup);
+static void devm_v4l2_subdev_cleanup(void *data)
+{
+ v4l2_subdev_cleanup(data);
+}
+
+int devm_v4l2_subdev_init_finalize(struct device *dev, struct v4l2_subdev *sd)
+{
+ int err;
+
+ err = v4l2_subdev_init_finalize(sd);
+ if (err)
+ return err;
+
+ return devm_add_action_or_reset(dev, devm_v4l2_subdev_cleanup, sd);
+}
+EXPORT_SYMBOL_GPL(devm_v4l2_subdev_init_finalize);
+
struct v4l2_mbus_framefmt *
__v4l2_subdev_state_get_format(struct v4l2_subdev_state *state,
unsigned int pad, u32 stream)
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 57f2bcb4eb16..a5da32783846 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1337,6 +1337,23 @@ void __v4l2_subdev_state_free(struct v4l2_subdev_state *state);
int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name,
struct lock_class_key *key);
+/**
+ * devm_v4l2_subdev_init_finalize - Managed finalization of V4L2 sub-device initialization
+ *
+ * @dev: Device that manages the lifecycle of the V4L2 sub-device.
+ * @sd: Pointer to the initialized V4L2 sub-device.
+ *
+ * This function finalizes the initialization of a V4L2 sub-device 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_subdev_init_finalize(), and simplifies
+ * resource management using devres.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int devm_v4l2_subdev_init_finalize(struct device *dev, struct v4l2_subdev *sd);
+
/**
* v4l2_subdev_cleanup() - Releases the resources allocated by the subdevice
* @sd: The subdevice
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/4] media: v4l2-ctrls: Add devm_v4l2_ctrl_handler_init() helper
2025-07-23 10:25 [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Tarang Raval
` (2 preceding siblings ...)
2025-07-23 10:25 ` [PATCH 3/4] media: v4l2-subdev: Add devm_v4l2_subdev_init_finalize() helper Tarang Raval
@ 2025-07-23 10:25 ` Tarang Raval
2025-07-23 12:55 ` [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Laurent Pinchart
4 siblings, 0 replies; 10+ messages in thread
From: Tarang Raval @ 2025-07-23 10:25 UTC (permalink / raw)
To: sakari.ailus, laurent.pinchart, hverkuil
Cc: Tarang Raval, Mauro Carvalho Chehab, Ricardo Ribalda,
Hans de Goede, Yunke Cao, James Cowgill, Tomi Valkeinen,
Lad Prabhakar, Tommaso Merciai, linux-media, linux-kernel
Add a devm-managed version of v4l2_ctrl_handler_init() to simplify control
handler initialization and cleanup using devres.
Signed-off-by: Tarang Raval <tarang.raval@siliconsignals.io>
---
drivers/media/v4l2-core/v4l2-ctrls-core.c | 20 ++++++++++++++++++++
include/media/v4l2-ctrls.h | 19 +++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 98b960775e87..2c8c46bc8d30 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -5,6 +5,7 @@
* Copyright (C) 2010-2021 Hans Verkuil <hverkuil-cisco@xs4all.nl>
*/
+#include <linux/device/devres.h>
#include <linux/export.h>
#include <linux/mm.h>
#include <linux/slab.h>
@@ -1671,6 +1672,25 @@ int v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
}
EXPORT_SYMBOL(v4l2_ctrl_handler_free);
+static void devm_v4l2_ctrl_handler_free(void *data)
+{
+ v4l2_ctrl_handler_free(data);
+}
+
+int devm_v4l2_ctrl_handler_init(struct device *dev,
+ struct v4l2_ctrl_handler *hdl,
+ unsigned int nr_of_controls_hint)
+{
+ int err;
+
+ err = v4l2_ctrl_handler_init(hdl, nr_of_controls_hint);
+ if (err)
+ return err;
+
+ return devm_add_action_or_reset(dev, devm_v4l2_ctrl_handler_free, hdl);
+}
+EXPORT_SYMBOL(devm_v4l2_ctrl_handler_init);
+
/* For backwards compatibility: V4L2_CID_PRIVATE_BASE should no longer
be used except in G_CTRL, S_CTRL, QUERYCTRL and QUERYMENU when dealing
with applications that do not use the NEXT_CTRL flag.
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index c32c46286441..dfb956a5ad9a 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -573,6 +573,25 @@ int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
#endif
+/**
+ * devm_v4l2_ctrl_handler_init - Managed initialization of V4L2 control handler
+ *
+ * @dev: Device that manages the lifecycle of the control handler.
+ * @hdl: Pointer to the V4L2 control handler to initialize.
+ * @nr_of_controls_hint: Estimated number of controls to be added.
+ *
+ * This function initializes a V4L2 control handler 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_ctrl_handler_init(), and simplifies resource
+ * management using devres.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int devm_v4l2_ctrl_handler_init(struct device *dev,
+ struct v4l2_ctrl_handler *hdl,
+ unsigned int nr_of_controls_hint);
/**
* v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
* the control list.
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems
2025-07-23 10:25 [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Tarang Raval
` (3 preceding siblings ...)
2025-07-23 10:25 ` [PATCH 4/4] media: v4l2-ctrls: Add devm_v4l2_ctrl_handler_init() helper Tarang Raval
@ 2025-07-23 12:55 ` Laurent Pinchart
2025-07-23 14:08 ` Tarang Raval
4 siblings, 1 reply; 10+ messages in thread
From: Laurent Pinchart @ 2025-07-23 12:55 UTC (permalink / raw)
To: Tarang Raval
Cc: sakari.ailus, hverkuil, Mauro Carvalho Chehab, Ricardo Ribalda,
Hans de Goede, James Cowgill, Yunke Cao, Tomi Valkeinen,
Lad Prabhakar, Tommaso Merciai, linux-media, linux-kernel
Hi Tarang,
On Wed, Jul 23, 2025 at 03:55:04PM +0530, Tarang Raval wrote:
> This patch series introduces devm-managed versions of several commonly used
> media and V4L2 initialization functions. These helpers simplify resource
> management by leveraging the devres infrastructure, ensuring automatic
> cleanup when the associated device is detached or the driver is unloaded.
I'll let Sakari review this, but overall, I don't think we want to take
this direction. Objects need to be refcounted instead of freed at remove
time. This patch series doesn't necessarily cause a regression as such,
but it will make it more difficult to fix life time management issues in
V4L2.
> Tested with IMX219 and OV2735 camera sensors on an i.MX8MP-based platform.
>
> Tarang Raval (4):
> media: mc: Add devm_media_entity_pads_init() helper
> media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper
> media: v4l2: subdev: Add devm_v4l2_subdev_init_finalize() helper
> media: v4l2-ctrls: Add devm_v4l2_ctrl_handler_init() helper
>
> drivers/media/mc/mc-entity.c | 19 +++++++++++++++++++
> drivers/media/v4l2-core/v4l2-async.c | 19 +++++++++++++++++++
> drivers/media/v4l2-core/v4l2-ctrls-core.c | 20 ++++++++++++++++++++
> drivers/media/v4l2-core/v4l2-subdev.c | 18 ++++++++++++++++++
> include/media/media-entity.h | 20 ++++++++++++++++++++
> include/media/v4l2-async.h | 18 ++++++++++++++++++
> include/media/v4l2-ctrls.h | 19 +++++++++++++++++++
> include/media/v4l2-subdev.h | 17 +++++++++++++++++
> 8 files changed, 150 insertions(+)
>
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems
2025-07-23 12:55 ` [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Laurent Pinchart
@ 2025-07-23 14:08 ` Tarang Raval
2025-07-27 16:48 ` sakari.ailus
0 siblings, 1 reply; 10+ messages in thread
From: Tarang Raval @ 2025-07-23 14:08 UTC (permalink / raw)
To: Laurent Pinchart
Cc: sakari.ailus@linux.intel.com, hverkuil@xs4all.nl,
Mauro Carvalho Chehab, Ricardo Ribalda, Hans de Goede,
James Cowgill, Yunke Cao, Tomi Valkeinen, Lad Prabhakar,
Tommaso Merciai, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org
Hi Laurent,
> On Wed, Jul 23, 2025 at 03:55:04PM +0530, Tarang Raval wrote:
> > This patch series introduces devm-managed versions of several commonly used
> > media and V4L2 initialization functions. These helpers simplify resource
> > management by leveraging the devres infrastructure, ensuring automatic
> > cleanup when the associated device is detached or the driver is unloaded.
>
> I'll let Sakari review this, but overall, I don't think we want to take
> this direction. Objects need to be refcounted instead of freed at remove
> time.
I agree that refcounting could provide more robust lifetime management,
especially for shared resources. I will think in this direction, explore
implementing refcounting for these objects, and share an RFC for your
feedback.
> This patch series doesn't necessarily cause a regression as such,
> but it will make it more difficult to fix life time management issues in
> V4L2.
Could you clarify how devm-managed helpers might complicate lifetime
management in V4L2? Understanding specific issues will help me design
a solution that aligns with the subsystem’s needs while keeping cleanup
simple.
Best Regards,
Tarang
> > Tested with IMX219 and OV2735 camera sensors on an i.MX8MP-based platform.
> >
> > Tarang Raval (4):
> > media: mc: Add devm_media_entity_pads_init() helper
> > media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper
> > media: v4l2: subdev: Add devm_v4l2_subdev_init_finalize() helper
> > media: v4l2-ctrls: Add devm_v4l2_ctrl_handler_init() helper
> >
> > drivers/media/mc/mc-entity.c | 19 +++++++++++++++++++
> > drivers/media/v4l2-core/v4l2-async.c | 19 +++++++++++++++++++
> > drivers/media/v4l2-core/v4l2-ctrls-core.c | 20 ++++++++++++++++++++
> > drivers/media/v4l2-core/v4l2-subdev.c | 18 ++++++++++++++++++
> > include/media/media-entity.h | 20 ++++++++++++++++++++
> > include/media/v4l2-async.h | 18 ++++++++++++++++++
> > include/media/v4l2-ctrls.h | 19 +++++++++++++++++++
> > include/media/v4l2-subdev.h | 17 +++++++++++++++++
> > 8 files changed, 150 insertions(+)
> >
>
> --
> Regards,
>
> Laurent Pinchart
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/4] media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper
2025-07-23 10:25 ` [PATCH 2/4] media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper Tarang Raval
@ 2025-07-25 0:13 ` kernel test robot
0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2025-07-25 0:13 UTC (permalink / raw)
To: Tarang Raval, sakari.ailus, laurent.pinchart, hverkuil
Cc: llvm, oe-kbuild-all, Tarang Raval, Mauro Carvalho Chehab,
linux-media, Ricardo Ribalda, Hans de Goede, Yunke Cao,
James Cowgill, Tomi Valkeinen, Lad Prabhakar, Tommaso Merciai,
linux-kernel
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems
2025-07-23 14:08 ` Tarang Raval
@ 2025-07-27 16:48 ` sakari.ailus
2025-07-28 5:45 ` Tarang Raval
0 siblings, 1 reply; 10+ messages in thread
From: sakari.ailus @ 2025-07-27 16:48 UTC (permalink / raw)
To: Tarang Raval
Cc: Laurent Pinchart, hverkuil@xs4all.nl, Mauro Carvalho Chehab,
Ricardo Ribalda, Hans de Goede, James Cowgill, Yunke Cao,
Tomi Valkeinen, Lad Prabhakar, Tommaso Merciai,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Hi Tarang,
Thanks for the patchset.
On Wed, Jul 23, 2025 at 02:08:03PM +0000, Tarang Raval wrote:
> Hi Laurent,
>
> > On Wed, Jul 23, 2025 at 03:55:04PM +0530, Tarang Raval wrote:
> > > This patch series introduces devm-managed versions of several commonly used
> > > media and V4L2 initialization functions. These helpers simplify resource
> > > management by leveraging the devres infrastructure, ensuring automatic
> > > cleanup when the associated device is detached or the driver is unloaded.
> >
> > I'll let Sakari review this, but overall, I don't think we want to take
> > this direction. Objects need to be refcounted instead of freed at remove
> > time.
>
> I agree that refcounting could provide more robust lifetime management,
> especially for shared resources. I will think in this direction, explore
> implementing refcounting for these objects, and share an RFC for your
> feedback.
I agree with Laurent here when it comes to the current state of the
patches.
Tearing down things automatically, however, is what we should look into.
But I believe it will require refcounting sub-devices first, then we could
bind such resources to them. But before this, we'll need to merge the media
device refcounting series
<URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=media-ref>.
>
> > This patch series doesn't necessarily cause a regression as such,
> > but it will make it more difficult to fix life time management issues in
> > V4L2.
>
> Could you clarify how devm-managed helpers might complicate lifetime
> management in V4L2? Understanding specific issues will help me design
> a solution that aligns with the subsystem’s needs while keeping cleanup
> simple.
The problem with devm_*() and UAPI is that once the device disappears, so
disappear all its resources, including those being used by whatever
programs accessing the UAPI, leading to memory safety issues. IOW devm_()
when used on memory resources in V4L2 is often simply wrong but right now
we don't have yet any better options in a lot of cases.
--
Kind regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems
2025-07-27 16:48 ` sakari.ailus
@ 2025-07-28 5:45 ` Tarang Raval
0 siblings, 0 replies; 10+ messages in thread
From: Tarang Raval @ 2025-07-28 5:45 UTC (permalink / raw)
To: sakari.ailus@linux.intel.com
Cc: Laurent Pinchart, hverkuil@xs4all.nl, Mauro Carvalho Chehab,
Ricardo Ribalda, Hans de Goede, James Cowgill, Yunke Cao,
Tomi Valkeinen, Lad Prabhakar, Tommaso Merciai,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
> On Wed, Jul 23, 2025 at 02:08:03PM +0000, Tarang Raval wrote:
> > Hi Laurent,
> >
> > > On Wed, Jul 23, 2025 at 03:55:04PM +0530, Tarang Raval wrote:
> > > > This patch series introduces devm-managed versions of several commonly used
> > > > media and V4L2 initialization functions. These helpers simplify resource
> > > > management by leveraging the devres infrastructure, ensuring automatic
> > > > cleanup when the associated device is detached or the driver is unloaded.
> > >
> > > I'll let Sakari review this, but overall, I don't think we want to take
> > > this direction. Objects need to be refcounted instead of freed at remove
> > > time.
> >
> > I agree that refcounting could provide more robust lifetime management,
> > especially for shared resources. I will think in this direction, explore
> > implementing refcounting for these objects, and share an RFC for your
> > feedback.
>
> I agree with Laurent here when it comes to the current state of the
> patches.
>
> Tearing down things automatically, however, is what we should look into.
> But I believe it will require refcounting sub-devices first, then we could
> bind such resources to them. But before this, we'll need to merge the media
> device refcounting series
> <URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=media-ref>.
Okay, I will wait for this series to be merged.
Thanks for the reference, I will go through these patches and follow the
progress.
> > > This patch series doesn't necessarily cause a regression as such,
> > > but it will make it more difficult to fix life time management issues in
> > > V4L2.
> >
> > Could you clarify how devm-managed helpers might complicate lifetime
> > management in V4L2? Understanding specific issues will help me design
> > a solution that aligns with the subsystem’s needs while keeping cleanup
> > simple.
>
> The problem with devm_*() and UAPI is that once the device disappears, so
> disappear all its resources, including those being used by whatever
> programs accessing the UAPI, leading to memory safety issues. IOW devm_()
> when used on memory resources in V4L2 is often simply wrong but right now
> we don't have yet any better options in a lot of cases.
Understood. Thanks for the clarification.
Best Regards,
Tarang
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-07-28 5:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 10:25 [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Tarang Raval
2025-07-23 10:25 ` [PATCH 1/4] media: mc: Add devm_media_entity_pads_init() helper Tarang Raval
2025-07-23 10:25 ` [PATCH 2/4] media: v4l: async: Add devm_v4l2_async_register_subdev_sensor() helper Tarang Raval
2025-07-25 0:13 ` kernel test robot
2025-07-23 10:25 ` [PATCH 3/4] media: v4l2-subdev: Add devm_v4l2_subdev_init_finalize() helper Tarang Raval
2025-07-23 10:25 ` [PATCH 4/4] media: v4l2-ctrls: Add devm_v4l2_ctrl_handler_init() helper Tarang Raval
2025-07-23 12:55 ` [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems Laurent Pinchart
2025-07-23 14:08 ` Tarang Raval
2025-07-27 16:48 ` sakari.ailus
2025-07-28 5:45 ` Tarang Raval
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox