[Concept,v2,05/30] video: Unregister cyclic on the last video-device removal

Message ID 20260102005112.552256-6-sjg@u-boot.org
State New
Headers
Series ext4l: Add write support (part L) |

Commit Message

Simon Glass Jan. 2, 2026, 12:50 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add a pre_remove() handler to unregister the video_idle() cyclic when
the last video device is removed. This ensures the cyclic won't run
after driver model is reinited by the test framework.

This complements the uclass_find() fix by properly cleaning up the
cyclic registration rather than just gracefully handling the orphaned
state.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

(no changes since v1)

 drivers/video/video-uclass.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
  

Patch

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 383be0d96b8..3e02c48d399 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -874,6 +874,23 @@  __maybe_unused static int video_destroy(struct uclass *uc)
 	return 0;
 }
 
+__maybe_unused static int video_pre_remove(struct udevice *dev)
+{
+	struct video_uc_priv *uc_priv = uclass_get_priv(dev->uclass);
+
+	/*
+	 * Unregister the cyclic before removing the last video device. This
+	 * ensures the cyclic won't run after driver model is reinitialised
+	 * by the test framework.
+	 */
+	if (uc_priv->cyc_active && uclass_id_count(UCLASS_VIDEO) == 1) {
+		cyclic_unregister(&uc_priv->cyc);
+		uc_priv->cyc_active = false;
+	}
+
+	return 0;
+}
+
 void video_set_manual_sync(bool enable)
 {
 	struct video_uc_priv *uc_priv;
@@ -897,5 +914,6 @@  UCLASS_DRIVER(video) = {
 	.priv_auto	= sizeof(struct video_uc_priv),
 	.per_device_auto	= sizeof(struct video_priv),
 	.per_device_plat_auto	= sizeof(struct video_uc_plat),
+	CONFIG_IS_ENABLED(CYCLIC, (.pre_remove = video_pre_remove, ))
 	CONFIG_IS_ENABLED(CYCLIC, (.destroy = video_destroy, ))
 };