[PATCH] media: em28xx: clear dev->v4l2 when v4l2 init fails

From: Haoli Zhang

Date: Fri Nov 13 2026 - 08:38:16 EST


em28xx_v4l2_init() publishes dev->v4l2 before the initialization is
complete. If a later step fails, the error path unregisters any video
nodes and drops the initial v4l2_device reference, but leaves dev->v4l2
set until the release callback runs.

em28xx_init_extension() does not propagate an extension init failure, and
em28xx_close_extension() later invokes the extension's fini() callback.
The extension init and close paths are serialized by
em28xx_devlist_mutex, so clearing dev->v4l2 before init returns makes the
later fini() see NULL and avoid another v4l2_device_put(). Otherwise, the
reference count can reach zero while a video node still holds a reference.

The open callback checks dev->v4l2 under dev->lock, so an open waiting for
init cleanup sees NULL and fails with -ENODEV. Clear dev->v4l2 while still
holding dev->lock to protect that check.

Fixes: 288254383674 ("media: em28xx: use v4l2_device release callback")
Reported-by: syzbot+54648a6c1187a7ef46a6@xxxxxxxxxxxxxxxxxxxxxxxxx
Link: https://syzkaller.appspot.com/bug?extid=54648a6c1187a7ef46a6
Cc: stable@xxxxxxxxxxxxxxx

Co-developed-by: Jinning Zhang <25031212117@xxxxxxxxxxxxxxxxx>
Signed-off-by: Jinning Zhang <25031212117@xxxxxxxxxxxxxxxxx>
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Haoli Zhang <26031212468@xxxxxxxxxxxxxxxxx>

---
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 47441e98173d330c773dede5596872ad85678649..046b52f1afc53bd5f5b3944194eb1b9eadeabea1 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -3127,10 +3127,15 @@
"V4L2 device %s deregistered\n",
video_device_node_name(&v4l2->vdev));
vb2_video_unregister_device(&v4l2->vdev);
}

+ /*
+ * Prevent open() from using this failed instance and fini() from
+ * dropping its initial reference a second time.
+ */
+ dev->v4l2 = NULL;
mutex_unlock(&dev->lock);

/*
* Drop the initial reference. em28xx_free_v4l2() will be called
* once the last video_device node release has decremented the
--
2.47.0