From: "sakari.ailus@linux.intel.com" <sakari.ailus@linux.intel.com>
To: Tarang Raval <tarang.raval@siliconsignals.io>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
"hverkuil@xs4all.nl" <hverkuil@xs4all.nl>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Ricardo Ribalda <ribalda@chromium.org>,
Hans de Goede <hansg@kernel.org>,
James Cowgill <james.cowgill@blaize.com>,
Yunke Cao <yunkec@google.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
Tommaso Merciai <tomm.merciai@gmail.com>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 0/4] media: Add devm-managed helper functions for media and V4L2 subsystems
Date: Sun, 27 Jul 2025 16:48:04 +0000 [thread overview]
Message-ID: <aIZYRJQNaNTXE3Cm@kekkonen.localdomain> (raw)
In-Reply-To: <PN3P287MB1829D71FB3C2B41FF28D6A198B5FA@PN3P287MB1829.INDP287.PROD.OUTLOOK.COM>
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
next prev parent reply other threads:[~2025-07-27 16:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-07-28 5:45 ` Tarang Raval
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=aIZYRJQNaNTXE3Cm@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=hansg@kernel.org \
--cc=hverkuil@xs4all.nl \
--cc=james.cowgill@blaize.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=ribalda@chromium.org \
--cc=tarang.raval@siliconsignals.io \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=tomm.merciai@gmail.com \
--cc=yunkec@google.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