[PATCH v2 2/2] media: uvcvideo: skip resume after hibernation snapshot
From: Haowen Tu
Date: Thu May 28 2026 - 04:20:21 EST
When a UVC camera is in active use and the system enters S4 hibernation,
the camera is suspended as part of the normal device freeze sequence.
However, after create_image() saves the memory snapshot, the kernel
briefly resumes all devices with PMSG_THAW to write the hibernation
image to storage. This causes uvc_video_resume() to run and
reinitialize the camera hardware, which visibly turns on the camera
indicator LED during this intermediate phase even though the system is
about to power off.
The UVC device is not needed during the image-write window, where the
system only needs devices required for writing the hibernation image.
USB .resume callbacks do not receive pm_message_t, unlike .suspend, so
use the PM-layer helper to detect this phase.
This is intentionally handled in uvcvideo rather than in USB core. USB
core cannot skip all interface resume callbacks during hibernation THAW,
because some USB interfaces may be part of the image writeout path or
otherwise be required by dependencies. uvcvideo has a concrete
user-visible side effect from reinitializing hardware in this transient
phase, and it is not involved in image writeout.
The check is placed after stream->frozen is cleared and the clock is
reset, so that driver state remains consistent if the image write fails
and the system resumes normally instead of powering off. In that case
userspace will need to restart the stream, but the driver will not be
left with stale frozen state.
Tested with hibernation image written to local storage and resumed from
disk on a system with a USB UVC camera attached; the camera LED remains
off during image writing and the video stream resumes correctly after
restore.
Signed-off-by: Haowen Tu <tuhaowen@xxxxxxxxxxxxx>
---
Changes in v2:
- Use pm_hibernation_snapshot_done() after the PM helper was renamed.
drivers/media/usb/uvc/uvc_video.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index f6c8e3223796..9fa649fd47e0 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -12,6 +12,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/slab.h>
+#include <linux/suspend.h>
#include <linux/usb.h>
#include <linux/usb/hcd.h>
#include <linux/videodev2.h>
@@ -2151,6 +2152,17 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
if (!uvc_queue_streaming(&stream->queue))
return 0;
+ /*
+ * During hibernation image writing (PMSG_THAW), the kernel briefly
+ * resumes devices after the snapshot has been created. Skip hardware
+ * reinitialization to avoid USB traffic and the spurious camera LED
+ * activation. stream->frozen has already been cleared, so if the
+ * image write fails and the system resumes normally, driver state
+ * remains consistent; userspace will need to restart the stream.
+ */
+ if (pm_hibernation_snapshot_done())
+ return 0;
+
ret = uvc_commit_video(stream, &stream->ctrl);
if (ret < 0)
return ret;
--
2.20.1