From: Matan Cohen <matan@matanco.space>
To: linux-staging@lists.linux.dev
Cc: parthiban.veerasooran@microchip.com,
christian.gromm@microchip.com, gregkh@linuxfoundation.org,
Matan Cohen <matan@matanco.space>
Subject: [PATCH] staging: most: video: replace BUG_ON with WARN_ON_ONCE and add recovery
Date: Mon, 20 Apr 2026 11:35:03 +0000 [thread overview]
Message-ID: <20260420113503.62552-1-matan@matanco.space> (raw)
BUG_ON() halts the kernel unconditionally. The check after
most_deregister_component() guards against a bug in mostcore: it
currently does not call disconnect_channel() for linked channels on
deregistration, so if that ever changes unexpectedly, video_devices
could be non-empty.
Replace BUG_ON with WARN_ON_ONCE so the kernel stays up, and add a
recovery path that drains and frees any remaining devices to avoid
memory leaks in that error case.
Also document what the spinlock and mutex in struct most_video_dev
each protect.
---
drivers/staging/most/video/video.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
index 04351f8ccccf1..4ade49569bd63 100644
--- a/drivers/staging/most/video/video.c
+++ b/drivers/staging/most/video/video.c
@@ -33,14 +33,14 @@ struct most_video_dev {
bool mute;
struct list_head pending_mbos;
- spinlock_t list_lock;
+ spinlock_t list_lock; /* protects pending_mbos and mute */
struct v4l2_device v4l2_dev;
atomic_t access_ref;
struct video_device *vdev;
unsigned int ctrl_input;
- struct mutex lock;
+ struct mutex lock; /* v4l2 device lock */
wait_queue_head_t wait_data;
};
@@ -577,7 +577,20 @@ static void __exit comp_exit(void)
most_deregister_configfs_subsys(&comp);
most_deregister_component(&comp);
- BUG_ON(!list_empty(&video_devices));
+
+ if (WARN_ON_ONCE(!list_empty(&video_devices))) {
+ /* clean up any devices unexpectedly added during deregister phase */
+ spin_lock_irq(&list_lock);
+ list_replace_init(&video_devices, &free_list);
+ spin_unlock_irq(&list_lock);
+
+ list_for_each_entry_safe(mdev, tmp, &free_list, list) {
+ list_del_init(&mdev->list);
+ comp_unregister_videodev(mdev);
+ v4l2_device_disconnect(&mdev->v4l2_dev);
+ v4l2_device_put(&mdev->v4l2_dev);
+ }
+ }
}
module_init(comp_init);
--
2.43.0
next reply other threads:[~2026-04-20 11:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 11:35 Matan Cohen [this message]
2026-04-20 12:35 ` [PATCH] staging: most: video: replace BUG_ON with WARN_ON_ONCE and add recovery Greg KH
2026-04-20 14:14 ` Dan Carpenter
2026-04-21 15:15 ` Matan Cohen
2026-04-21 15:22 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260420113503.62552-1-matan@matanco.space \
--to=matan@matanco.space \
--cc=christian.gromm@microchip.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-staging@lists.linux.dev \
--cc=parthiban.veerasooran@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox