All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ian Rogers <irogers@google.com>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hans@jjverkuil.nl>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@iki.fi>
Subject: Re: [PATCH] [RFC] media: Drop v4l2_file_operations owner field
Date: Fri, 4 Dec 2026 14:04:45 +0900	[thread overview]
Message-ID: <20261204050445.GC597403@killaraus.ideasonboard.com> (raw)
In-Reply-To: <CAP-5=fVZz0Cdb-_AyhPtLzTX-XNPtROcZ+5E0v3OM230unjE3g@mail.gmail.com>

On Thu, Dec 03, 2026 at 08:17:00PM -0800, Ian Rogers wrote:
> On Thu, Dec 3, 2026 at 6:18 PM Laurent Pinchart wrote:
> > The owner field of the v4l2_file_operations structure is used only by
> > the video_register_device() and video_register_device_no_warn() wrappers
> > to pass the owning module to the __video_register_device() function. It
> > has to be set by drivers to THIS_MODULE, in order to properly refcount
> > modules an open() and release() time.
> >
> > The V4L2 core silently accepts a NULL owner, making this very
> > error-prone. Multiple driver forgot to set the owner field, resulting in
> > refcounting issues that have been unnoticed for years.
> >
> > We could fix those individual drivers, but the problem would be likely
> > to occur again in the future. Fix it by making the error impossible
> > instead: remove the owner field, and pass THIS_MODULE to
> > __video_register_device() from the wrapper functions.
> >
> > The changes to drivers was generated with the following Coccinelle
> > semantic patch:
> >
> > @@
> > identifier fops;
> > @@
> > struct v4l2_file_operations fops = {
> >         ...,
> > -       .owner = THIS_MODULE,
> >         ...
> > };
> >
> > The only other change in this commit is the removal of the owner field
> > and the changes to the wrapper functions in include/media/v4l2-dev.h.
> >
> > Reported-by: Ian Rogers <irogers@google.com>
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> Hi Laurent,
> 
> Sorry — I replied to your earlier message before seeing this RFC!
> 
> Removing v4l2_file_operations::owner altogether and passing
> THIS_MODULE directly from video_register_device() is even cleaner than
> annotating .owner with __must_init, since it eliminates the bug class
> at the API level (and works for GCC too).
> 
> Two quick things I spotted while checking the tree:
> 
> 1. drivers/media/radio/tea575x.c:532 (tea->fops.owner = owner;) and
> drivers/media/radio/radio-tea5777.c:556 (tea->fops.owner = owner;)
> weren't caught by the Coccinelle rule because they assign .owner at

I know, I should have mentioned it was a quick RFC. I didn't want to
spent time auditing every driver before getting feedback on the general
approach. If people like the idea, I'll send a v2.

> runtime from the caller's struct module *owner. Since both are helper
> modules registering on behalf of a parent driver, they'll need
> __video_register_device(..., 1, owner) directly instead of
> video_register_device() (which also lets them drop copying
> tea575x_fops into mutable tea->fops).
> 2. For my 5-patch series: patches 1–4 may still be useful for stable
> backports (since this tree-wide refactor won't backport), and patch 5
> (media: sunxi: a83t-mipi-csi2) fixes struct phy_ops::owner rather than
> v4l2_file_operations, so it's independent of this RFC.
> 
> Thanks for putting this together!
> Ian

-- 
Regards,

Laurent Pinchart

      reply	other threads:[~2026-12-04  5:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:18 [PATCH] [RFC] media: Drop v4l2_file_operations owner field Laurent Pinchart
2026-12-04  4:17 ` Ian Rogers
2026-12-04  5:04   ` Laurent Pinchart [this message]

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=20261204050445.GC597403@killaraus.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hans@jjverkuil.nl \
    --cc=irogers@google.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@iki.fi \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.