Re: [PATCH 1/5] media: amlogic: c3-isp: Set .owner = THIS_MODULE in v4l2_file_operations

From: Ian Rogers

Date: Thu Dec 03 2026 - 22:03:39 EST


On Thu, Dec 3, 2026 at 5:57 PM Laurent Pinchart
<laurent.pinchart@xxxxxxxxxxxxxxxx> wrote:
>
> On Thu, Dec 03, 2026 at 09:15:43AM -0800, Ian Rogers wrote:
> > video_register_device() passes vdev->fops->owner to
> > __video_register_device(), which sets vdev->cdev->owner = owner so
> > chrdev_open() pins the V4L2 driver module while the device node is open.
> > When .owner is omitted in a const struct v4l2_file_operations,
> > vdev->cdev->owner is NULL and the driver module is not reference counted
> > on open().
> >
> > Set .owner = THIS_MODULE in isp_cap_v4l2_fops, isp_params_v4l2_fops, and
> > isp_stats_v4l2_fops, found with Clang's require_explicit_initialization
> > attribute.
>
> This sounds like a game of whack-a-mole. A better solution would be to
> improve the API to make this error impossible in the first place. I'll
> send an RFC.

So the intent is to use __must_init an attribute that will cause
compilation with clang to fail if the given variable isn't initialized
when the struct is created. This should make the error impossible, but
before I can add the attribute I need to fix the places where
initialization is missing.

For context, I gave this presentation at LPC:
https://lpc.events/event/20/contributions/2392/
And the series adding the attribute is here, with the first user being
kobject::release:
https://lore.kernel.org/lkml/20261119192520.1983406-1-irogers@xxxxxxxxxx/

Thanks,
Ian

>
> > Fixes: fb2e135208f3 ("media: platform: Add C3 ISP driver")
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
> > drivers/media/platform/amlogic/c3/isp/c3-isp-capture.c | 1 +
> > drivers/media/platform/amlogic/c3/isp/c3-isp-params.c | 1 +
> > drivers/media/platform/amlogic/c3/isp/c3-isp-stats.c | 1 +
> > 3 files changed, 3 insertions(+)
> >
> > diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-capture.c b/drivers/media/platform/amlogic/c3/isp/c3-isp-capture.c
> > index 11d85f5342f0..da0506548d34 100644
> > --- a/drivers/media/platform/amlogic/c3/isp/c3-isp-capture.c
> > +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-capture.c
> > @@ -502,6 +502,7 @@ static const struct v4l2_file_operations isp_cap_v4l2_fops = {
> > .poll = vb2_fop_poll,
> > .unlocked_ioctl = video_ioctl2,
> > .mmap = vb2_fop_mmap,
> > + .owner = THIS_MODULE,
> > };
> >
> > static int c3_isp_cap_link_validate(struct media_link *link)
> > diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c
> > index ae0777a20bda..686f22c99d69 100644
> > --- a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c
> > +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c
> > @@ -764,6 +764,7 @@ static const struct v4l2_file_operations isp_params_v4l2_fops = {
> > .poll = vb2_fop_poll,
> > .unlocked_ioctl = video_ioctl2,
> > .mmap = vb2_fop_mmap,
> > + .owner = THIS_MODULE,
> > };
> >
> > static int c3_isp_params_vb2_queue_setup(struct vb2_queue *q,
> > diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-stats.c b/drivers/media/platform/amlogic/c3/isp/c3-isp-stats.c
> > index 8a5d7e1a30c9..888a4a6434e8 100644
> > --- a/drivers/media/platform/amlogic/c3/isp/c3-isp-stats.c
> > +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-stats.c
> > @@ -140,6 +140,7 @@ static const struct v4l2_file_operations isp_stats_v4l2_fops = {
> > .poll = vb2_fop_poll,
> > .unlocked_ioctl = video_ioctl2,
> > .mmap = vb2_fop_mmap,
> > + .owner = THIS_MODULE,
> > };
> >
> > static int c3_isp_stats_vb2_queue_setup(struct vb2_queue *q,
>
> --
> Regards,
>
> Laurent Pinchart