Skip to contentSkip to conversation

media: v4l2-async: don't unbind an already unbound device

PATCH New Hans Verkuil 1 participant 1 message Oct 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l2-async: don't unbind an already unbound device

In __v4l2_async_register_subdev() we call v4l2_async_match_notify to notify a matched subdev. That function tries to register and bind to the device, but on error it will leave the device unregistered and unbound.

However, __v4l2_async_register_subdev() will try to unbind the device if v4l2_async_match_notify() returned an error. That fails with a kernel oops.

Set 'asc' to NULL to prevent the unbind step from happening.

Found by testing omap3isp on a Beagle xM board *without* the mt9p031 camera connected. In that case the internal_ops->registered callback returns -ENODEV and you get a kernel oops:

[    5.811462] mt9p031 1-0048: MT9P031 not detected, wrong version 0xffffff87
[    5.818664] 8<--- cut here ---
[    5.821746] Unable to handle kernel NULL pointer dereference at virtual address 00000004 when write
[    5.830932] [00000004] *pgd=00000000
[    5.834594] Internal error: Oops: 805 [#1] SMP ARM
[    5.839447] Modules linked in:
[    5.842559] CPU: 0 UID: 0 PID: 25 Comm: kworker/u4:1 Not tainted 6.17.0-arm #8 NONE
[    5.850402] Hardware name: Generic OMAP36xx (Flattened Device Tree)
[    5.856719] Workqueue: events_unbound deferred_probe_work_func
[    5.862640] PC is at v4l2_async_unbind_subdev_one+0x54/0xc0
[    5.868316] LR is at v4l2_async_unbind_subdev_one+0xa0/0xc0

<snip>

[    6.198181] Call trace:
[    6.198211]  v4l2_async_unbind_subdev_one from __v4l2_async_register_subdev+0x144/0x19c
[    6.208862]  __v4l2_async_register_subdev from mt9p031_probe+0x490/0x564
[    6.215667]  mt9p031_probe from i2c_device_probe+0x168/0x308
[    6.221405]  i2c_device_probe from really_probe+0xc8/0x2c8
[    6.226989]  really_probe from __driver_probe_device+0x88/0x1a0
[    6.233001]  __driver_probe_device from driver_probe_device+0x30/0x104
[    6.239624]  driver_probe_device from __device_attach_driver+0x94/0x108
[    6.246307]  __device_attach_driver from bus_for_each_drv+0x84/0xd8
[    6.252685]  bus_for_each_drv from __device_attach+0xa8/0x1a4
[    6.258483]  __device_attach from bus_probe_device+0x88/0x8c
[    6.264251]  bus_probe_device from deferred_probe_work_func+0x78/0xa4
[    6.270751]  deferred_probe_work_func from process_one_work+0x178/0x3bc
[    6.277496]  process_one_work from worker_thread+0x27c/0x450
[    6.283264]  worker_thread from kthread+0x118/0x244
[    6.288238]  kthread from ret_from_fork+0x14/0x28

---
Note: I'm not sure if this a the best approach to fix this. Suggestions are welcome. I also can't figure out when this issue was introduced. It might have been there since the beginning.

---
 drivers/media/v4l2-core/v4l2-async.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-async.c +3 -1
index ee884a8221fb..ccf47d240b89 100644
@@ -828,8 +828,10 @@ int __v4l2_async_register_subdev(struct v4l2_subdev *sd, struct module *module)
 		while ((asc = v4l2_async_find_match(notifier, sd))) {
 			ret = v4l2_async_match_notify(notifier, v4l2_dev, sd,
 						      asc);
-			if (ret)
+			if (ret) {
+				asc = NULL;
 				goto err_unbind;
+			}
 
 			ret = v4l2_async_nf_try_complete(notifier);
 			if (ret)
Signature · 1 line
2.51.0