linux/drivers/media/v4l2-core
Mirela Rabulea 06cb687a51 media: v4l2-fwnode: Fix subdev owner overwritten in v4l2_async_register_subdev_sensor()
The v4l2 helper v4l2_async_register_subdev_sensor() calls
v4l2_async_register_subdev(), which is a macro that expands to
__v4l2_async_register_subdev(sd,THIS_MODULE). Since the macro is expanded
inside v4l2-fwnode.c, THIS_MODULE resolves to the v4l2-fwnode module
rather than the sensor driver module that originally set sd->owner. When
v4l2-fwnode is built-in, THIS_MODULE evaluates to NULL, which then
overwrites the sensor driver's owner with NULL.

This causes the problem that the sensor module's reference count is never
incremented during async registration, so the module can be removed while
the subdevice is still in use by a notifier (e.g., a CSI-2 receiver
bridge driver).

Fix this by renaming v4l2_async_register_subdev_sensor() to
__v4l2_async_register_subdev_sensor() with an added explicit module
argument and introducing a wrapper macro:
    #define v4l2_async_register_subdev_sensor(sd) \
        __v4l2_async_register_subdev_sensor(sd, THIS_MODULE)

This ensures the sensor driver module is properly referenced even when
the sensor driver does not init the owner field before calling
v4l2_async_register_subdev_sensor() and prevents premature module removal.

Fixes: aef69d5475 ("media: v4l: fwnode: Add a convenience function for registering sensors")
Cc: stable@vger.kernel.org
Suggested-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/linux-media/20240315073125.275501-2-sakari.ailus@linux.intel.com/
Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
2026-06-05 10:28:03 +03:00
..
Kconfig media: v4l2-core: Introduce v4l2-isp.c 2025-11-14 15:48:48 +01:00
Makefile media: v4l2-core: Introduce v4l2-isp.c 2025-11-14 15:48:48 +01:00
tuner-core.c media: Use named initializers for arrays of i2c_device_data 2026-05-20 09:03:40 +02:00
v4l2-async.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
v4l2-cci.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
v4l2-common.c media: v4l2-common: add v4l2_fill_pixfmt_mp_aligned helper 2026-05-21 12:32:19 +02:00
v4l2-compat-ioctl32.c media: update Hans Verkuil's email address 2025-09-09 15:59:02 +02:00
v4l2-ctrls-api.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
v4l2-ctrls-core.c media: v4l2-ctrls: validate HEVC active reference counts 2026-05-04 08:35:14 +02:00
v4l2-ctrls-defs.c media: v4l2-controls: Add control for background detection 2026-05-04 08:35:14 +02:00
v4l2-ctrls-priv.h media: v4l2-core: update Hans Verkuil's email address 2025-09-09 15:58:38 +02:00
v4l2-ctrls-request.c media: v4l2-ctrls-request: add NULL check in v4l2_ctrl_request_complete() 2026-05-06 09:17:37 +02:00
v4l2-dev.c media: v4l2-dev: Add range check for vdev->minor 2026-05-12 09:39:02 +02:00
v4l2-device.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
v4l2-dv-timings.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
v4l2-event.c Convert 'alloc_flex' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
v4l2-fh.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
v4l2-flash-led-class.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
v4l2-fwnode.c media: v4l2-fwnode: Fix subdev owner overwritten in v4l2_async_register_subdev_sensor() 2026-06-05 10:28:03 +03:00
v4l2-h264.c
v4l2-i2c.c media: v4l2-core: Replace the check for firmware registered I2C devices 2025-06-17 10:35:13 +02:00
v4l2-ioctl.c media: mc, v4l2: serialize REINIT and REQBUFS with req_queue_mutex 2026-03-18 11:21:31 +01:00
v4l2-isp.c media: v4l2-isp: Rename block_info to block_type_info 2025-11-14 15:48:49 +01:00
v4l2-jpeg.c media: v4l2-jpeg: Remove unused v4l2_jpeg_parse_* wrappers 2025-06-17 10:35:17 +02:00
v4l2-mc.c media: mc: fix endpoint iteration 2024-12-19 12:50:17 +01:00
v4l2-mem2mem.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
v4l2-spi.c media: v4l: Set sub-device's owner field to the caller's module 2024-04-26 11:30:43 +01:00
v4l2-subdev-priv.h
v4l2-subdev.c media: v4l2-subdev: Allow accessing routes with STREAMS client capability 2026-05-07 13:23:50 +03:00
v4l2-trace.c
v4l2-vp9.c