Skip to content

Commit caea6bc

Browse files
mrabule1gregkh
authored andcommitted
media: v4l2-fwnode: Fix subdev owner overwritten in v4l2_async_register_subdev_sensor()
commit 06cb687 upstream. 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: aef69d5 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dbaf0e0 commit caea6bc

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

drivers/media/v4l2-core/v4l2-fwnode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ v4l2_async_nf_parse_fwnode_sensor(struct device *dev,
12051205
return 0;
12061206
}
12071207

1208-
int v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd)
1208+
int __v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd, struct module *module)
12091209
{
12101210
struct v4l2_async_notifier *notifier;
12111211
int ret;
@@ -1231,7 +1231,7 @@ int v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd)
12311231
if (ret < 0)
12321232
goto out_cleanup;
12331233

1234-
ret = v4l2_async_register_subdev(sd);
1234+
ret = __v4l2_async_register_subdev(sd, module);
12351235
if (ret < 0)
12361236
goto out_unregister;
12371237

@@ -1249,7 +1249,7 @@ int v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd)
12491249

12501250
return ret;
12511251
}
1252-
EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor);
1252+
EXPORT_SYMBOL_GPL(__v4l2_async_register_subdev_sensor);
12531253

12541254
MODULE_DESCRIPTION("V4L2 fwnode binding parsing library");
12551255
MODULE_LICENSE("GPL");

include/media/v4l2-async.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,10 @@ int __v4l2_async_register_subdev(struct v4l2_subdev *sd, struct module *module);
333333
* An error is returned if the module is no longer loaded on any attempts
334334
* to register it.
335335
*/
336+
#define v4l2_async_register_subdev_sensor(sd) \
337+
__v4l2_async_register_subdev_sensor(sd, THIS_MODULE)
336338
int __must_check
337-
v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd);
339+
__v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd, struct module *module);
338340

339341
/**
340342
* v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous

0 commit comments

Comments
 (0)